Skip to main content

Security & Compliance

2 min read

Security & Compliance Overview

Directive provides security guardrails and compliance tooling for AI agent systems. Detect threats at the input layer, audit every operation, and handle data subject requests.


Security Features

FeaturePageThreat Addressed
PII DetectionInput/output scanningPersonally identifiable information leaking to/from agents
Prompt InjectionInput validationJailbreaks, instruction overrides, encoding evasion
Audit TrailObservabilityTamper-evident logging of every system operation
GDPR/CCPAData governanceRight to erasure, data export, consent tracking, retention

Defense in Depth

Apply multiple layers of protection:

User Input
  → Prompt Injection Detection  (block attacks before they reach agents)
  → PII Detection               (redact sensitive data from input)
  → Agent Execution              (safe to process after filtering)
  → Output PII Scan             (catch any data leaks in responses)
  → Audit Trail                 (log every operation for compliance)

Quick Setup

import { createAgentOrchestrator } from '@directive-run/ai';
import { createEnhancedPIIGuardrail, createPromptInjectionGuardrail } from '@directive-run/ai';

const orchestrator = createAgentOrchestrator({
  runner: myRunner,

  // Input guardrails run in order before each agent invocation
  guardrails: {
    input: [
      // First line of defense: block injection attacks
      createPromptInjectionGuardrail({ strictMode: true }),

      // Second pass: redact any PII that slipped through
      createEnhancedPIIGuardrail({ redact: true }),
    ],
  },
});

When to Use What

ScenarioFeature
User-facing chatbotPII detection + prompt injection + audit trail
Internal toolAudit trail + GDPR compliance
Healthcare/financeAll four features
Development/testingAudit trail only

Server vs. Browser

All security features use globalThis.crypto.subtle (Web Crypto API) and work in both environments:

FeatureServer (Node 18+)BrowserPrimary Use
PII DetectionYesYesBoth – input/output scanning
Prompt InjectionYesYesBoth – input validation
Audit TrailYesYesPrimarily server – tamper-evident logs, SIEM export
GDPR/CCPA ComplianceYesYesPrimarily server – data export, deletion certificates

Node 18+ is required for crypto.subtle. No Node-specific imports are used – the same code runs in Deno and Bun as well.

Audit trails and compliance tooling are most useful on the server where you control the data layer. PII detection and prompt injection prevention are equally valuable in both environments. See the Server (Node.js) example for a full API demonstrating all four features together.


Next Steps

  • Start with safetyPII Detection is the most common first step
  • Add attack preventionPrompt Injection for user-facing apps
  • Compliance requirements?GDPR/CCPA for regulated industries
Previous
RAG Enricher

We care about your data. We'll never share your email.

Powered by Directive. This signup uses a Directive module with facts, derivations, constraints, and resolvers – zero useState, zero useEffect. Read how it works

Directive - Constraint-Driven State Management for TypeScript