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
| Feature | Page | Threat Addressed |
|---|---|---|
| PII Detection | Input/output scanning | Personally identifiable information leaking to/from agents |
| Prompt Injection | Input validation | Jailbreaks, instruction overrides, encoding evasion |
| Audit Trail | Observability | Tamper-evident logging of every system operation |
| GDPR/CCPA | Data governance | Right 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
| Scenario | Feature |
|---|---|
| User-facing chatbot | PII detection + prompt injection + audit trail |
| Internal tool | Audit trail + GDPR compliance |
| Healthcare/finance | All four features |
| Development/testing | Audit trail only |
Server vs. Browser
All security features use globalThis.crypto.subtle (Web Crypto API) and work in both environments:
| Feature | Server (Node 18+) | Browser | Primary Use |
|---|---|---|---|
| PII Detection | Yes | Yes | Both – input/output scanning |
| Prompt Injection | Yes | Yes | Both – input validation |
| Audit Trail | Yes | Yes | Primarily server – tamper-evident logs, SIEM export |
| GDPR/CCPA Compliance | Yes | Yes | Primarily 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 safety – PII Detection is the most common first step
- Add attack prevention – Prompt Injection for user-facing apps
- Compliance requirements? – GDPR/CCPA for regulated industries

