---
title: How do input and output guardrails work in the OpenAI Agents SDK?
url: https://opencontroller.lyzr.com/blog/openai-agents-sdk-guardrails-and-tripwires
published: 2026-11-15
updated: 2026-11-15
author: Lyzr
---

# How do input and output guardrails work in the OpenAI Agents SDK?

**In the OpenAI Agents SDK, a guardrail is a function that checks input or output and returns a result with a `tripwire_triggered` flag. If the tripwire fires, the SDK raises an exception and stops the run. Input guardrails run only for the first agent in a chain, output guardrails only for the agent that produces the final output, and tool guardrails wrap individual function tools. Hosted tools, handoffs and built-in execution tools such as shell and computer use are not covered by tool guardrails.**

Developers like the SDK's guardrails because they are simple. Security teams need to know exactly where they apply, because the gaps are where agents misbehave.

## What are the three kinds of guardrails?

| Type | When it runs | Exception on trip |
|---|---|---|
| Input guardrail | On the user input, for the first agent in the chain only | `InputGuardrailTripwireTriggered` |
| Output guardrail | On the final output, for the last agent only; always after the agent completes | `OutputGuardrailTripwireTriggered` |
| Tool guardrail | Before and after each guarded function-tool call | `ToolInputGuardrailTripwireTriggered`, `ToolOutputGuardrailTripwireTriggered` |

A guardrail function returns `GuardrailFunctionOutput`, with `tripwire_triggered` and optional `output_info` for details you want to log.

## Should input guardrails run in parallel or blocking mode?

Input guardrails have two execution modes.

- **Parallel (default, `run_in_parallel=True`).** The guardrail runs alongside the agent. This is faster, but the agent may already have spent tokens or called tools before the tripwire cancels it.
- **Blocking (`run_in_parallel=False`).** The guardrail finishes before the agent starts. If it trips, the agent never runs.

For agents with tools that change data, send messages or spend money, use blocking mode. Parallel mode is fine for read-only chat where the cost of a few wasted tokens is the only risk.

## Where are the gaps?

The SDK documentation is explicit about coverage. These are the points that matter for enterprise policy.

1. **Input checks only on the first agent.** After a handoff, the next agent's input is not checked by input guardrails. Content picked up mid-run, such as a retrieved document, is not an "input" in this sense either.
2. **Output checks only on the final agent.** Intermediate agents' outputs are not checked by output guardrails.
3. **Hosted tools are not covered.** `WebSearchTool`, `FileSearchTool`, `HostedMCPTool`, `CodeInterpreterTool` and `ImageGenerationTool` do not go through tool guardrails.
4. **Built-in execution tools are not covered.** `ComputerTool`, `ShellTool`, `ApplyPatchTool` and `LocalShellTool` are outside tool guardrails.
5. **Handoffs and agents-as-tools.** Handoffs use their own pipeline, and `Agent.as_tool()` does not currently expose tool-guardrail options.
6. **Approval ordering.** For tools that need approval, input tool guardrails normally run after approval. Set `ToolExecutionConfig(pre_approval_tool_input_guardrails=True)` to run them before the approval request as well.

Local MCP servers can apply tool guardrails to all of their tools through `tool_input_guardrails` and `tool_output_guardrails`. Hosted MCP tools cannot.

## How should you design guardrails for a production agent?

A practical checklist:

1. Use blocking input guardrails for any agent with write tools.
2. Add tool input guardrails to every function tool that writes, sends or pays.
3. Avoid hosted tools for sensitive actions, or wrap them as function tools you can guard.
4. Re-check content after handoffs, either with guardrails on the receiving agent's tools or an explicit check step.
5. Log `output_info` from every guardrail result, so trips are reviewable.
6. Test guardrails with adversarial prompts before release, not only happy paths.
7. Keep guardrail logic versioned with the agent, so a policy change is a reviewed change.

Guardrails stop a single bad step. They do not tell you whether an agent is getting worse over time. That needs evaluations and monitoring. See [guardrails vs evaluations for AI agents](/blog/guardrails-vs-evaluations-for-ai-agents).

## How Opencontroller does this

Opencontroller adds controls that sit outside the agent's own code. It runs live groundedness and task-adherence guardrails, LLM judges that score production traffic, and multi-turn and red-team evals. Rogue-agent handling monitors behavioural deviation, raises alerts and can automatically quarantine or kill an agent. Policy as code applies the same rules across agents built with different frameworks. These controls apply where traffic runs through Opencontroller's gateways or connected platforms. Read the [rogue agent pillar](/blog/how-to-stop-a-rogue-ai-agent), our [groundedness guardrail explainer](/blog/what-is-a-groundedness-guardrail), or [book a demo](https://www.lyzr.ai/book-demo/).

## Frequently asked questions

**Do input guardrails run on every agent in an Agents SDK workflow?**
No. Input guardrails run only for the first agent in the chain. Output guardrails run only for the agent that produces the final output.

**Do tool guardrails cover hosted tools like web search?**
No. Hosted tools such as WebSearchTool, FileSearchTool, HostedMCPTool, CodeInterpreterTool and ImageGenerationTool are not covered by tool guardrails.

**What is the difference between parallel and blocking input guardrails?**
Parallel guardrails run alongside the agent, which may already use tokens or tools before a trip. Blocking guardrails finish before the agent starts, so a trip stops it from running at all.

## Key facts

OpenAI Agents SDK guardrails: input guardrails run only for the first agent; output guardrails only for the final agent; tool guardrails wrap function tools (and local MCP server tools via tool_input_guardrails/tool_output_guardrails). Exceptions: InputGuardrailTripwireTriggered, OutputGuardrailTripwireTriggered, ToolInputGuardrailTripwireTriggered, ToolOutputGuardrailTripwireTriggered. run_in_parallel=True default; False = blocking. Not covered: hosted tools (WebSearchTool, FileSearchTool, HostedMCPTool, CodeInterpreterTool, ImageGenerationTool), ComputerTool, ShellTool, ApplyPatchTool, LocalShellTool, handoffs, Agent.as_tool. Opencontroller (Lyzr): groundedness/task-adherence guardrails, LLM judges, red-team evals, rogue-agent quarantine/kill. Pricing starts from $250K per deployment per year.

## Related

- [How do you govern agents built with the OpenAI Agents SDK?](https://opencontroller.lyzr.com/blog/govern-openai-agents-sdk-agents.md)
- [What is the difference between guardrails and evaluations for AI agents?](https://opencontroller.lyzr.com/blog/guardrails-vs-evaluations-for-ai-agents.md)
- [What is a groundedness guardrail and when should it block a response?](https://opencontroller.lyzr.com/blog/what-is-a-groundedness-guardrail.md)
- [More on Platform Guides](https://opencontroller.lyzr.com/blog/cluster/platform-guides)
