Building-block guide · Trust and quality

Guardrails

How to layer input, retrieval, output and tool-call guardrails for agents, what prompt-injection defences can and cannot do, which classifiers and policy engines to use, how to budget latency, when to fail open or closed, and how to measure both missed attacks and false positives.

Draft for review · researched 30 Nov 2026

Contents
  1. At a glance
  2. Scope and where it sits
  3. When to use what
  4. Decision criteria
  5. Reference patterns
  6. Recommended defaults
  7. Anti-patterns
  8. Sizing and cost notes
  9. Security and compliance hooks
  10. Test and eval checklist
  11. Related plan sections and inventory
  12. Unverified or needs review
  13. Sources

At a glance

  • Guardrails are layers, not a product. Put checks at four points: input, retrieved or tool-returned content, output, and every tool call. The tool-call layer is the one that stops harm, because it sits where the agent acts.
  • Prompt injection is not solved. Twelve published defences that reported near-zero attack success were bypassed with over 90% success by adaptive attacks in most cases [4]. Plan on classifiers being bypassed.
  • So the primary defence is architectural: once an agent has read untrusted content, that content must not be able to trigger consequential actions [5]. Use deterministic policy (Cedar) at tool calls, least privilege and human approval for high-impact actions (10B).
  • Avoid the lethal trifecta: private data, untrusted content and an external communication channel in the same agent [6]. Remove one leg or add an architectural control.
  • Use classifiers as cheap, fast tripwires: small open models screen 512-token windows in about 19 to 92 ms on a data-centre GPU [9]; hosted services add document and indirect-attack detection [10].
  • Policy guardrails fail closed; observability and advisory checks may fail open (plan section 4B). Write the rule down per check.
  • Measure false positives as seriously as misses. Over-defensive guard models fell to about 60% accuracy on benign prompts containing trigger words [13]. Track block rates, appeals and task success.
  • Map every control to OWASP LLM Top 10 2025 [1] and the OWASP Top 10 for Agentic Applications 2026 [3], and red-team with adaptive attacks before release and on every change.

Scope and where it sits

This guide covers runtime controls that inspect or constrain what goes into a model, what comes back from retrieval and tools, what the model produces, and what the agent is allowed to do. It covers prompt-injection defences, content safety, PII and DLP, deterministic policy at tool calls, latency budgets, failure modes, red-teaming and false-positive measurement.

In the 10-layer reference architecture guardrails live mainly in layer 9, Trust, safety and policy, are enforced at the layer 2 agent gateway (input and output screening, PII redaction, policy enforcement points) and are measured in layer 10, Observability, evaluation and governance. In the Anatomy crosswalk the primary system is the Immune system (detection and containment), with Proprioception (telemetry on blocks and near misses) and Guardianship and law (policy, autonomy limits and approvals).

Covered elsewhere:

When to use what

Option Use when Avoid when Cost/latency notes
Deterministic policy at tool calls (Cedar, OPA) Any agent that acts; allow or deny by principal, action, resource and context (10B) Never skip for write tools Sub-millisecond to low milliseconds per decision (practitioner default); no model call
Architectural patterns (plan-then-execute, dual LLM, map-reduce, code-then-execute) Agents that read untrusted content and also hold consequential tools [5][7] Low-risk read-only assistants where utility loss is not justified Some utility loss; one study solved 77% of tasks with provable security against 84% undefended [7]
Small open injection classifier Fast first-pass screening of user input and retrieved chunks [9] As the only defence; non-English text if the model was not trained on it 19 to 92 ms per 512 tokens on an A100 [9]; self-hosted
Hosted prompt-attack and content service Managed screening for direct and document-borne attacks, content safety and PII [10] Data that may not leave your boundary; regions where the service is unavailable Network call per check; per-request pricing
LLM-as-judge or guard model Nuanced policy (topic, tone, advice limits) where rules fail Hot path for every token; anything needing determinism Highest latency and cost; run asynchronously where possible
Spotlighting or datamarking Marking untrusted content so the model can tell it from instructions [8][10] As a guarantee; low-capacity models with encoding Few extra tokens; base64 encoding adds more [10]
PII detection and redaction (Presidio, cloud DLP) Inputs, retrieved content, tool arguments and outputs with personal data [14] Assuming complete detection; the project itself says it cannot guarantee finding everything [14] Regex and NER are fast; LLM-based detection slower
Programmable rail frameworks Orchestrating input, retrieval, dialog, execution and output rails in one place [12] Teams wanting a thin, hand-written pipeline Adds framework overhead; parallel rails reduce latency
Human approval Irreversible, financial, external-communication or privilege-changing actions (14) High-volume low-risk actions (approval fatigue) Minutes to hours; budget reviewer capacity

Decision criteria

  1. What can the agent do? Read-only agents need input, retrieval and output guardrails. Agents with write, send or pay tools also need deterministic policy at every tool call and approvals by tier.
  2. Does it combine private data, untrusted content and external communication? If yes, remove a leg (no egress, no untrusted input or no private data) or adopt an architectural pattern before relying on classifiers [5][6].
  3. What is the cost of a miss versus a false block? High-impact actions: fail closed and accept friction. Advisory content checks: fail open with logging.
  4. Where may data be sent for screening? Hosted classifiers process prompts and documents; check residency and retention. Self-host where data cannot leave.
  5. What latency budget does the journey allow? Interactive chat tolerates tens of milliseconds per check in the hot path; batch agents tolerate more. Run independent checks in parallel.
  6. Which languages and modalities? Some classifiers are trained mainly on English [10]; screenshots and images need multimodal checks or human confirmation [8].
  7. Is the policy expressible as a rule? If yes, code it (Cedar, schema validation, allow-lists). Use models only for what rules cannot express.
  8. Can you measure it? Every guardrail needs a labelled benign set and an attack set, and logged decisions in production.

Reference patterns

1. Four-layer guardrail pipeline

Problem. A single input filter misses indirect injection from tools and retrieval, and does nothing about what the agent actually does.

How it works. Place checks at four points:

Layer Checks Failure mode
Input Jailbreak and prompt-attack classifier, topic and content policy, PII detection, size and rate limits Block or ask to rephrase
Retrieval and tool results Indirect-injection classifier on documents and tool outputs, provenance tags, hidden-text stripping, datamarking Drop or quarantine the item; continue
Output Content safety, PII and secret redaction, groundedness for factual answers, Markdown and link allow-list Redact, regenerate or block
Action (tool call) Cedar policy on principal, action, resource and context; argument schema validation; risk-tier approvals; rate and budget limits Fail closed; deny and log

NeMo Guardrails names a similar set of rail types (input, retrieval, dialog, execution, output) [12]. In the OpenAI Agents SDK, agent-level input guardrails run only for the first agent and output guardrails only for the last; tool guardrails are needed to cover every custom tool call in multi-agent runs, and input guardrails can run in parallel with the model (the default) or block it first [15].

When to use. Every production agent; layers scale with the agent's risk tier.

Pitfalls. Screening only the user's message; screening outputs but not tool arguments; one shared threshold for every surface.

2. Deterministic policy at the tool call

Problem. Model-based guardrails are probabilistic and can be bypassed; the place where harm happens is the tool call.

How it works. Every tool call passes an enforcement point outside the agent's loop that evaluates Cedar policy: the user's grant, the agent's grant and the delegation chain, with default deny and fail closed (plan controls AZ-1 to AZ-7, 10B). Context includes taint ("this plan was influenced by untrusted content"), risk tier, amount and destination. The MCP specification likewise expects clients to show tool inputs, confirm sensitive operations, validate results, apply timeouts and log calls [16].

// Illustrative: block external sends once untrusted content is in context
forbid (principal, action == Action::"email.send", resource)
when { context.tainted_by_untrusted && resource.recipient_domain != "internal.example" };

When to use. Any agent with write, send, pay or delete tools.

Pitfalls. Policy inside the prompt; enforcement in the agent process the model can influence; missing taint propagation from retrieval to action.

3. Constrain after untrusted input

Problem. Classifiers miss novel injections, and adaptive attackers find bypasses [4].

How it works. Choose a design pattern so untrusted content cannot change which actions run [5]:

  • Plan-then-execute: fix the plan from the user's request before reading untrusted data.
  • Dual LLM: a privileged model never sees untrusted text; a quarantined model processes it and returns symbolic variables.
  • Map-reduce: isolated sub-agents process each untrusted item and return constrained outputs (labels, numbers).
  • Code-then-execute: the privileged model writes a program; data flows are tracked and policy is checked at tool calls (the CaMeL approach) [7].
  • Context minimisation: drop untrusted content from context once it is no longer needed.

When to use. Email, browsing, ticket and document agents with any consequential tool.

Pitfalls. Patterns cost utility; the design-patterns paper says general-purpose agents are unlikely to offer reliable guarantees with current models [5]. Pick per use case and record the choice.

4. Tiered classifier cascade

Problem. Running a large guard model on every input and output is slow and expensive; running nothing leaves obvious attacks through.

How it works. Run a small, fast classifier on everything; escalate only uncertain or high-risk items to a larger model or hosted service; send blocks above a confidence threshold straight to deny. Small open classifiers are fast: one 22M-parameter model scores 512 tokens in 19.3 ms and its 86M sibling in 92.4 ms on an A100, with 88.7% and 97.5% recall at 1% false-positive rate on the vendor's evaluation [9]. One frontier lab moved its safety classifiers to a cascade of cheap internal probes and a stronger second stage, cutting compute overhead to about 1% (from 23.7%) and harmless-traffic refusals to 0.05% [11].

When to use. High-volume assistants and gateways.

Pitfalls. Classifier windows (512 tokens) shorter than the content, so long documents need chunking [9]; classifiers that detect only injection and jailbreaks being treated as content-safety filters [9]; vendor numbers taken as your numbers.

5. PII and DLP at every boundary

Problem. Agents move personal data from retrieval into prompts, tool arguments, logs and outputs.

How it works. Detect and redact or tokenise personal data in prompts, retrieved chunks and tool arguments before they reach a model or a third-party tool; re-identify only inside trusted tools that need the real value. Scan outputs and egress (links, images, emails) for personal data and secrets. Presidio combines recognisers (regex, NER and checksums) and supports custom ones, but states that it cannot guarantee finding all sensitive information [14]. Pair detection with permission-aware retrieval so the agent never sees what the user cannot (Permission-aware retrieval and residency). Inventory: Data privacy, PII and DLP for agents.

When to use. Any agent touching customer, employee or patient data.

Pitfalls. Redacting prompts but logging raw traces; redaction that breaks tasks (names needed to send an email); relying on detection alone where access control should apply.

6. Continuous red-teaming and false-positive monitoring

Problem. Guardrail tuning drifts: thresholds set once go stale as attacks, models and traffic change.

How it works. Before release, run automated and manual adaptive attacks per surface (direct chat, documents, web, tools, images), reporting success by number of attempts, since one vendor reports injection success ranging from 0% in a constrained coding setting to 78.6% for computer use after 200 attempts without safeguards [19]. In production, track block rate, false-positive rate from appeals and sampled reviews, and task success with and without each guardrail. Microsoft's red team stresses that red teaming is not benchmarking and the work is never complete [17]. Feed every bypass into a regression suite. Include indirect-injection techniques seen in the wild, which security researchers now track as live attacks rather than lab results [20].

When to use. Every guardrail in production.

Pitfalls. Static attack lists only; testing the classifier, not the end-to-end agent; no benign set, so false positives go unmeasured.

Setting Default Range or options Why
Tool-call policy Cedar default deny, fail closed None for write tools Plan AZ-1; sourced plan control
Policy hook failure Fail closed None Plan section 4B
Advisory and observability checks Fail open with alert Fail closed for high-risk surfaces Plan section 4B; practitioner default
Untrusted content handling Provenance tags plus datamarking; injection screen on every chunk Encoding only with high-capacity models Spotlighting cut attack success from over 50% to under 2% in one study [8]
Classifier first pass Small open classifier on input and retrieved content Hosted service where data may leave Latency [9]; practitioner default
Classifier window 512 tokens with chunking Model-specific Sourced [9]
Hot-path guardrail budget 100 ms p95 in total for interactive journeys 50 to 300 ms Practitioner default
Execution mode Input checks in parallel with the model; tool and action checks blocking Blocking input for high-risk agents Sourced options [15]; choice is practitioner default
False-positive target Under 1% of benign traffic blocked per guardrail Set per surface Practitioner default; vendor evaluations quote recall at 1% FPR [9]
Hosted screening threshold Start in annotate or log-only mode, then enforce Per category Annotate mode exists for tuning false positives [10]
System prompt in screening Do not send the system prompt to prompt-attack screening None Sourced [10]
PII handling Redact or tokenise before model and third-party tools Mask, hash, synthetic Sourced detection limits [14]; practitioner default
Approvals Required for irreversible, financial, external-send and privilege actions By autonomy tier Plan section 14
Red-team cadence Before each release and quarterly Monthly for A3 and A4 Practitioner default

Anti-patterns

  • Treating a classifier as the security boundary. Fix: deterministic policy at tool calls and architectural patterns; classifiers as tripwires [4][5].
  • Screening only the user's message. Fix: screen retrieved documents, tool outputs, emails and pages too [10].
  • Guardrails only on the first and last agent. Fix: tool guardrails on every tool call across handoffs [15].
  • Putting policy in the system prompt. Fix: enforcement point outside the agent loop (10B).
  • Fail-open policy checks "for availability". Fix: fail closed for policy; degrade the feature, not the control.
  • Rendering arbitrary Markdown images and links. Fix: link and image allow-lists; EchoLeak used crafted content to exfiltrate data and got past classifiers [18].
  • One global threshold. Fix: per-surface thresholds tuned on labelled benign and attack sets.
  • No false-positive measurement. Fix: benign set with trigger words, appeals channel, sampled review [13].
  • Testing with static jailbreak lists only. Fix: adaptive, multi-attempt red-teaming per surface [4][19].
  • Logging raw prompts with personal data. Fix: redact before logging; restrict trace access.
  • Approval prompts for everything. Fix: tier approvals; monitor approval load (OWASP T10 overwhelming HITL) (14).

Sizing and cost notes

  • Latency. Illustrative budget for an interactive turn: input classifier 20 to 90 ms [9] in parallel with the first model call; retrieval screening 20 to 90 ms per batch of chunks, run in parallel; tool-call policy in low milliseconds; output PII and content checks 20 to 100 ms. Sequential stacking of three hosted checks at 100 to 200 ms each adds noticeable delay, so parallelise and cascade.
  • Compute. A cascade can keep guardrail compute small relative to the main model: one lab reports about 1% overhead for its production classifier cascade [11].
  • Hosted services. Most are priced per request or per 1,000 text records. Illustrative: 1 million turns a month with three screened items each is 3 million screening calls; at a hypothetical USD 0.50 per 1,000 calls that is USD 1,500 a month. Check current rates and whether documents count per page or per chunk.
  • People. Appeals review, red-team time and policy maintenance are the larger ongoing cost. Plan reviewer capacity for false positives and approvals.
  • False-positive cost. At 1% false positives on 1 million turns, 10,000 users a month are blocked wrongly. Estimate the cost of each (abandonment, support contact) when tuning thresholds.

Security and compliance hooks

Risk OWASP mapping Guardrail and control
Direct and indirect prompt injection LLM01 Prompt injection [1]; ASI01 Agent goal hijack [3] Classifiers, datamarking, architectural patterns, tool-call policy
Leakage of personal or confidential data LLM02 Sensitive information disclosure; LLM07 System prompt leakage PII and DLP, output redaction, link allow-lists, permission-aware retrieval
Dangerous output passed to systems LLM05 Improper output handling Schema validation, encoding, sandboxed execution
Agent does too much LLM06 Excessive agency; ASI02 Tool misuse; ASI03 Identity and privilege abuse Least-privilege tools, Cedar, approvals
Poisoned retrieval or memory LLM04 Data and model poisoning; LLM08 Vector and embedding weaknesses; ASI06 Memory and context poisoning Provenance, retrieval screening, write controls on memory
Hallucinated or misleading answers LLM09 Misinformation; ASI09 Human-agent trust exploitation Groundedness checks, citations, clear uncertainty, approval wording
Runaway cost or loops LLM10 Unbounded consumption Rate limits, budgets, envelopes (14A)
Compromised components LLM03 Supply chain; ASI04 Agentic supply chain Allow-listed MCP servers and models, signed artefacts
Untraceable actions OWASP agentic threat T8 repudiation Logged guardrail decisions per run

OWASP has published a 2026 LLM list page with a revised order [2]; until its status is confirmed, map to the 2025 list and the 2026 agentic list.

Data protection. Screening services process user content: record them as processors, check residency, and prefer self-hosted classifiers for restricted data. Guardrail logs contain the very content they flagged; apply the same retention and access controls as traces.

Audit evidence to keep. Guardrail configuration and thresholds per release, policy bundles and their tests, labelled benign and attack sets with results, production block and false-positive metrics, red-team reports with fixes, and decision logs per run.

Governing plan sections. 10 Security (control catalogue), 10A Identity, 10B Cedar (fail-closed enforcement), 10C Network (egress and screening placement), 11 (data protection), 13 (registry records each agent's guardrail profile), 14 and 14A (approvals, envelopes, response ladder), 7 Evaluation (red-team and eval gates), and ROE (to be defined, plan section 12) as the outer policy the guardrails enforce.

Test and eval checklist

  • [ ] Threat model (Design). Each agent mapped to OWASP LLM and agentic risks; lethal-trifecta legs recorded. Pass: model reviewed and signed off.
  • [ ] Pattern choice (Design). Agents reading untrusted content with consequential tools use a documented architectural pattern. Pass: pattern recorded.
  • [ ] Failure mode per check (Design). Each guardrail marked fail open or fail closed with a reason. Pass: 100% documented; policy checks fail closed.
  • [ ] Policy tests (Build). Cedar policies unit-tested with allow and deny fixtures, including fail-closed cases. Pass: all green.
  • [ ] Direct injection (Test). Attack set on user input. Pass: success rate below agreed threshold.
  • [ ] Indirect injection (Test). Attacks in documents, web pages, emails and tool outputs. Pass: no consequential action taken without approval.
  • [ ] Adaptive attacks (Test). Multi-attempt, adaptive attacks per surface, with success reported by attempt count [4]. Pass: within threshold at k attempts.
  • [ ] Exfiltration channels (Test). Markdown images, links, tool arguments and emails. Pass: blocked by allow-lists and DLP.
  • [ ] False positives (Test). Benign set including trigger words and domain jargon. Pass: under target FPR per guardrail [13].
  • [ ] Languages (Test). Attack and benign sets in each supported language. Pass: within thresholds per language.
  • [ ] PII (Test). Seeded personal data in inputs, retrieval and tool arguments. Pass: recall at or above target; no PII in logs.
  • [ ] Latency (Release). Guardrail stack within the hot-path budget at peak load. Pass: p95 within budget.
  • [ ] Outage (Release). Simulate classifier or policy service outage. Pass: policy fails closed; advisory checks fail open and alert.
  • [ ] Multi-agent coverage (Release). Guardrails fire for intermediate agents and after handoffs. Pass: 100% coverage [15].
  • [ ] Monitoring (Run). Block rate, false-positive rate, appeals and bypasses on a dashboard. Pass: alerts configured.
  • [ ] Regression (Run). Every confirmed bypass added to the regression suite. Pass: suite run on each change.
  • [ ] Recurring red team (Run). Scheduled red-team exercises. Pass: completed on cadence with fixes tracked.

Governing policies and procedures

From the CoE policy set (draft; control IDs on the policy crosswalk):

Unverified or needs review

  • The OWASP 2026 LLM Top 10 page [2] exists with a revised order, but the downloadable document still links to the 2025 edition; its release status is unclear. This guide maps to the 2025 list.
  • The OWASP agentic threat identifiers (T1 to T15) come from CoE research notes, not reopened here.
  • CaMeL figures [7], spotlighting figures [8], EchoLeak [18], vendor system-card injection rates [19] and the CSA in-the-wild note [20] come from CoE research notes, not reopened for this guide.
  • The plan states that Model Armor inline screening fails open in regions where it is unavailable; not re-verified here. Confirm before relying on it as a fail-closed control.
  • Classifier latency and recall figures are the vendors' own evaluations on their hardware and data [9][11]; measure on your traffic.
  • The 100 ms hot-path budget, 1% false-positive target, red-team cadence and hosted pricing example are practitioner defaults or illustrative figures for the CoE lead to calibrate.
  • Azure Prompt Shields document detection defaults and tool-response support (preview) were read on one documentation page [10]; check current status per region.

Sources

  1. OWASP Top 10 for LLM Applications 2025. OWASP GenAI Security Project. https://genai.owasp.org/llm-top-10/, accessed 30 Nov 2026.
  2. OWASP Top 10 for LLM Applications 2026. OWASP GenAI Security Project. https://genai.owasp.org/top-10-for-llm-applications-2026/, accessed 30 Nov 2026.
  3. OWASP Top 10 for Agentic Applications (2026 edition, released 9 Dec 2025). OWASP GenAI Security Project. https://genai.owasp.org/resource/owasp-top-10-for-agentic-applications-for-2026/, accessed 30 Nov 2026.
  4. Nasr, Carlini et al., The attacker moves second: stronger adaptive attacks bypass defenses against LLM jailbreaks and prompt injections. arXiv 2510.09023 (10 Oct 2025). https://arxiv.org/abs/2510.09023, accessed 30 Nov 2026.
  5. Beurer-Kellner et al., Design patterns for securing LLM agents against prompt injections. arXiv 2506.08837 (June 2025), summarised by Simon Willison. https://simonwillison.net/2025/Jun/13/prompt-injection-design-patterns/, accessed 30 Nov 2026.
  6. The lethal trifecta for AI agents. Simon Willison (16 Jun 2025). https://simonwillison.net/2025/Jun/16/the-lethal-trifecta/, accessed 30 Nov 2026 (via CoE research notes).
  7. Debenedetti et al., Defeating prompt injections by design (CaMeL). arXiv 2503.18813. https://arxiv.org/abs/2503.18813, accessed 30 Nov 2026 (via CoE research notes).
  8. Hines et al., Defending against indirect prompt injection attacks with spotlighting. arXiv 2403.14720. https://arxiv.org/abs/2403.14720, accessed 30 Nov 2026 (via CoE research notes).
  9. Llama Prompt Guard 2 86M model card. Meta, Hugging Face. https://huggingface.co/meta-llama/Llama-Prompt-Guard-2-86M, accessed 30 Nov 2026.
  10. Prompt Shields in Azure AI Content Safety. Microsoft Learn. https://learn.microsoft.com/azure/ai-services/content-safety/concepts/jailbreak-detection, accessed 30 Nov 2026.
  11. Next-generation Constitutional Classifiers. Anthropic (9 Jan 2026). https://www.anthropic.com/research/next-generation-constitutional-classifiers, accessed 30 Nov 2026.
  12. Rail types. NVIDIA NeMo Guardrails documentation. https://docs.nvidia.com/nemo/guardrails/latest/about-nemo-guardrails-library/rail-types.html, accessed 30 Nov 2026.
  13. Li and Liu, InjecGuard: benchmarking and mitigating over-defense in prompt injection guardrail models. arXiv 2410.22770. https://arxiv.org/abs/2410.22770, accessed 30 Nov 2026.
  14. Presidio: data protection and de-identification SDK. Presidio project. https://presidio.dataprivacystack.org/, accessed 30 Nov 2026.
  15. Guardrails. OpenAI Agents SDK documentation. https://openai.github.io/openai-agents-python/guardrails/, accessed 30 Nov 2026.
  16. Tools. Model Context Protocol specification 2026-07-28. https://modelcontextprotocol.io/specification/2026-07-28/server/tools, accessed 30 Nov 2026.
  17. Lessons from red teaming 100 generative AI products. Microsoft AI Red Team, arXiv 2501.07238. https://arxiv.org/abs/2501.07238, accessed 30 Nov 2026 (via CoE research notes).
  18. Researchers detail zero-click Copilot exploit EchoLeak. Dark Reading (June 2025). https://www.darkreading.com/application-security/researchers-detail-zero-click-copilot-exploit-echoleak, accessed 30 Nov 2026 (via CoE research notes).
  19. Prompt injection becomes a measurable security metric. VentureBeat (10 Feb 2026), reporting a frontier model system card. https://venturebeat.com/security/prompt-injection-measurable-security-metric-one-ai-developer-publishes-numbers, accessed 30 Nov 2026 (via CoE research notes).
  20. CSA research note: indirect prompt injection in the wild (26 Apr 2026). Cloud Security Alliance. https://labs.cloudsecurityalliance.org/research/csa-research-note-indirect-prompt-injection-in-the-wild-2026/, accessed 30 Nov 2026 (via CoE research notes).
↑