Skip to main content
← Guides

Guardrails for agents

Guardrails & safety

Input, output, and tool-level defenses, tripwires that halt on trigger, and the cost trade-off between parallel and blocking checks.

What this guide covers

Guardrails mean putting checks on an agent's inputs and outputs, intercepting failures on the spot. They are a different thing from evaluation: evaluation measures "how good", guardrails police "is this allowed at all". Models err and can be manipulated; guardrails are engineering's last gate.

Three lines of defense

The OpenAI Agents SDK official docs define guardrails as "Guardrails enable you to do checks and validations of user input and agent output." In practice they split into three kinds, each standing at a different position.

Input guardrails: check the user's raw input, effective only on the first agent in the chain. Output guardrails: check the agent's final output, effective only on the last agent. Tool guardrails: wrap a specific function tool, checked before and after every call.

The official docs deliberately call out a common misconception: if the flow has a manager, handoffs, or delegated specialist agents, expecting agent-level input/output guardrails to fire at every hop is a disappointment — for a "check before every tool call" effect, you need tool guardrails.

Tripwires: halt on trigger

The core mechanism of guardrails is the tripwire. When a check fails, the runner immediately raises the corresponding exception and halts execution:

Defense lineException raised
Input guardrailInputGuardrailTripwireTriggered
Output guardrailOutputGuardrailTripwireTriggered
Tool input guardrailToolInputGuardrailTripwireTriggered
Tool output guardrailToolOutputGuardrailTripwireTriggered

The exception carries context: which guardrail tripped, and the list of results completed before the trip. The integrating side catches the exception and decides how to respond to the user.

A guardrail can also call an external classifier directly, without spinning up another agent. The official example scenario is representative: in front of an expensive customer-service model, hang a fast-model guardrail that blocks abuse like "write my math homework" outright.

Parallel or blocking

Input guardrails have two run modes, and the official docs spell out the cost difference.

Parallel execution (default): the guardrail and the agent run together, lowest latency. But when it trips, the agent may already have burned tokens and executed tools.

Blocking execution: the guardrail finishes first, the agent starts after. Trip and halt — no tokens spent, no tool side effects. OpenAI official text: blocking execution "is ideal for cost optimization and when you want to avoid potential side effects from tool calls".

Note output guardrails do not support the parallel flag — they always run after the agent completes.

What runs the check

At the code level it is a function plus a verdict; at the model level it can be an LLM acting as a classifier. The Llama Guard paper (arXiv 2312.06674) represents this route: an instruction-tuned safety classifier with its own risk taxonomy (taxonomy), multi-label classification over prompts and responses, emitting binary verdicts.

Paper abstract text: "matches or exceeds that of currently available content moderation tools". Note these are late-2023 paper results; with today's models and scenarios you must re-verify yourself.

Design discipline

  1. Guardrails police "allowed or not" — don't let them drift into "how good"; that is evaluation's job.
  2. Checks must be fast: a guardrail in front of the main flow must not itself become the latency hotspot.
  3. Failures must be visible: what was blocked and why must leave a trace, or false positives cannot be debugged.
  4. Don't guard only the front door: tool calls, handoffs, delegations — every hop can be an entry point.

One last official reminder worth keeping on the desk: Anthropic official text: "The autonomous nature of agents means higher costs, and the potential for compounding errors." Guardrails are not a cure-all, but they are the hand that pins compounding errors down at the first step.

Sources

SourceURL
OpenAI Agents SDK official docs · Guardrails (direct fetch 200 on 2026-10-30)https://openai.github.io/openai-agents-python/guardrails/
Llama Guard paper (arXiv 2312.06674, abstract page direct-fetched 2026-10-30)https://arxiv.org/abs/2312.06674
Anthropic engineering blog · Building effective agents (official page verified via WebFetch on 2026-10-30)https://www.anthropic.com/engineering/building-effective-agents

Source snapshot: 2026-10-30; 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.