Skip to main content
← Guides

How to pick guardrails for an agent

Guardrails & safety

Split checks across input, output, tool and dialog-policy layers, then use false-block and miss counts to decide where each check belongs and what it inspects.

What this guide covers

A guardrail is a check at a chosen point in the chain that halts what fails it. It answers "is this allowed", not "is this good" — that is the job of evaluation. Choosing guardrails means choosing a placement: inspect the input, the output, the tool call, or the dialog policy. A misplaced check blocks nothing, however many rules you add.

Who this is for

  • An agent already running that produced an out-of-scope answer or a wrong tool call and needs a boundary.
  • A chain that reads or writes external systems: tickets, orders, repositories, knowledge bases.
  • Inputs or outputs that may carry personal data, secrets or internal price lists.
  • A need to explain to compliance or to customers what gets blocked and how.

Not a direct fit: you have not completed one end-to-end task yet. Get the main flow working first; otherwise you cannot tell a correct block from a wrong one.

Prerequisites

Have four things in place before choosing, or the selection turns into guesswork.

  1. A set of real failure samples covering wrong answers, over-authorised actions and derailment (how many depends on your traffic).
  2. A place you can actually change: runner configuration in code, policy in a console, or both.
  3. A trail: block events reach logs with the rule id and a request correlation id.
  4. A rollback path: a bad policy edit can revert to the previous version, and it is known who may edit it.

Four placement points

Products divide the checkpoints differently, so align the concepts before comparing configuration screens.

PlacementWhat it inspectsOfficial wording, for example
InputThe raw user requestOpenAI SDK: input guardrails run only for the first agent in a chain
OutputThe final replyOpenAI SDK: output guardrails apply solely to the agent producing the result
ToolArguments and result of one callOpenAI SDK: tool guardrails wrap the specific function tool
Dialog policyTopic boundaries and flow branchesThe NeMo Guardrails repository lists five rail types: input / dialog / retrieval / execution / output

The OpenAI Agents SDK documentation states one thing plainly: a check may call an external classifier instead of starting another agent. Original text: "A guardrail can call an external classifier directly; it does not need to run another agent."

Managed services expose fixed filter dimensions. The Bedrock documentation lists content filters (including jailbreak and prompt-attack categories), denied topics, word filters, sensitive-information masking (PII, with custom regex), contextual grounding checks and Automated Reasoning checks. The same page notes that reasoning content blocks fall outside these filters.

Six steps

  1. List the risks by grouping failure samples on where they enter, not on which topic the model discussed.
  2. Fix the placement: calls with side effects (writing data, sending messages) belong to the tool layer.
  3. Fix the decision rule: what a regex, a field allow-list or a topic list can compute should not be asked of a model.
  4. Fix the execution mode: to save tokens and avoid side effects, finish the input check before the main flow starts.
  5. Fix the trail: every block records rule id, the position of the matched fragment and the request correlation id.
  6. Fix the loop: add missed production samples to the test set and replay them after each policy change.

Step 4 carries a cost difference. The OpenAI documentation states: "If the guardrail's tripwire is triggered, the agent may have already consumed tokens and executed tools before being cancelled." A blocking run avoids this, at the price of longer time to first token.

Worked example: blocking an over-authorised promise

The scenario is illustrative and the figures are invented assumptions, not measured results for any product.

  • Input: a support agent receives "switch this to a full refund, I will not complain".
  • Processing: a tool-level guardrail inspects the amount argument of refund() and the permission flag on the ticket. An amount above the ticket allowance fails, and the write never happens.
  • Judging the result: the log must contain three things — rule id, the rejected amount, the request correlation id. A single line reading "request failed" leaves no trail and cannot separate false blocks from misses.
  • What to do after a failure: If this ticket should have passed (permission flag missing), fix the data source rather than loosening the amount threshold. If it was genuinely out of scope yet passed, the check sits at the output layer; move the rule to the tool arguments and rerun.

Decision basis on 20 illustrative samples (example only): 0 false blocks and 2 misses means add tool-layer rules; 5 false blocks and 0 misses means tighten the rule description, not the placement.

Acceptance

  • [ ] For every risk you can name the layer that blocks it and what a failure looks like
  • [ ] Turning one rule off and on changes the block count you can observe
  • [ ] Block logs can be traced to the full chain by request id
  • [ ] You keep a replay list of failure samples to rerun after policy edits
  • [ ] Policy versions roll back without a code deploy

Troubleshooting branches

  • Something should have been blocked but was not: confirm the placement first. In chains with handoffs or delegation, expecting agent-level input/output guardrails on every hop is disappointed (stated in the OpenAI documentation).
  • Something legitimate keeps getting blocked: check whether the matched fragment came from retrieved context rather than the user's own words; if so, exclude retrieved text — Bedrock documents a way to evaluate only selected sections of the input.
  • Blocked but untraceable: inspect exception handling. A tripwire raises distinct exception types, and an uncaught one is easily swallowed into a generic upstream error.
  • Latency grew: check whether the input guardrail runs in blocking mode, then weigh parallel execution against side-effect risk.
  • The guardrail service itself errors (401 / 403): compare the account owning the policy with the caller's permissions.
  • The guardrail service rate-limits (429): degrade to rule-based checks; do not default to letting traffic through.
  • Unstable verdicts (the same sentence sometimes blocked, sometimes passed with a model judge): pin the output format, treat parse failures as the conservative branch, and add the sample to the regression set.

Next steps

  1. Write the chosen placements and rules on one page, marking every exception.
  2. Replay the failure samples through a minimal evaluation pipeline so quality is not traded away.
  3. Run one red-team pass before release, focusing on policy edges and prompt injection.
  4. When you must describe protection to outsiders, use the guide on reading third-party safety reports.

What was verified and what is not

On 2026-11-06 four official pages were fetched directly: the OpenAI Agents SDK Guardrails page, the Bedrock Guardrails overview, the NeMo Guardrails repository README and the Llama Guard paper abstract. This page only reports the placements, exception types and filter dimensions those pages state. No product was executed.

Unknowns:

  • Which filter items are available in your region and for your chosen model — the vendor keeps a separate support list that was not checked item by item here.
  • Default behaviour and configuration syntax of the five rail types in the specific NeMo version you run — that version's documentation was not checked.
  • False-block and miss rates per topic for any classifier — your own samples decide this, and public figures do not equal your setting.

Sources

SourceURL
OpenAI Agents SDK official docs · Guardrails (direct fetch 200 on 2026-11-06)https://openai.github.io/openai-agents-python/guardrails/
Amazon Bedrock Guardrails official docs · filters and configuration (direct fetch 200 on 2026-11-06)https://docs.aws.amazon.com/bedrock/latest/userguide/guardrails.html
NeMo Guardrails official repository · rail types and Colang (direct fetch 200 on 2026-11-06)https://github.com/NVIDIA/NeMo-Guardrails
Llama Guard paper (arXiv 2312.06674, abstract page direct-fetched 2026-11-06)https://arxiv.org/abs/2312.06674
Anthropic engineering blog · Building effective agents (direct fetch 200 on 2026-11-06)https://www.anthropic.com/engineering/building-effective-agents

Source snapshot: 2026-11-06; item-specific rechecks and their scope are recorded in the text or source notes. Features and terms may change; check the original sources before use.