Skip to main content

Security & Compliance

3 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.


Threat Model

A unified view of the threats Directive's security features address:

ThreatAttack VectorMitigationFeature
Data exfiltrationAgent leaks PII in outputOutput scanning with redactionPII Detection
PII in promptsUser submits personal dataInput scanning with redactionPII Detection
Prompt injectionAttacker embeds instructions in inputPattern detection, encoding analysisPrompt Injection
JailbreakUser overrides system promptStrict mode, known-attack patternsPrompt Injection
Encoding evasionBase64, Unicode smugglingMulti-encoding detectionPrompt Injection
Unaudited operationsNo record of what agents didTamper-evident logging, HMAC chainAudit Trail
Data subject requestsGDPR right to erasure / exportAutomated data deletion + exportGDPR/CCPA
Runaway costsAgent enters infinite loopToken budgets, circuit breakersSelf-Healing
Unsafe tool callsAgent invokes dangerous toolsTool-call guardrails, deny listsGuardrails

Layered Defense Strategy

Layer 1: Input Validation
  └─ Prompt injection detection (block attacks before they reach agents)
  └─ PII detection with redaction (scrub sensitive data from input)

Layer 2: Execution Controls
  └─ Tool-call guardrails (restrict which tools agents can invoke)
  └─ Token budgets + circuit breakers (prevent runaway costs)
  └─ Approval workflows (human-in-the-loop for high-risk actions)

Layer 3: Output Validation
  └─ Output guardrails (catch data leaks, enforce format)
  └─ Streaming guardrails (halt streams mid-generation)

Layer 4: Observability & Compliance
  └─ Audit trail with HMAC integrity chain
  └─ GDPR/CCPA data export and deletion
  └─ OpenTelemetry spans for every operation

Next Steps

Previous
DevTools

Stay in the loop. Sign up for our newsletter.

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 Runtime for TypeScript | AI Guardrails & State Management