An input guardrail screens what comes in; an output guardrail validates what goes out. The SDK Agent class takes both inputGuardrails and outputGuardrails, so the same checker-agent shape works on either side: a small agent answers a yes-or-no question about the reply, and the guardrail trips when the answer is yes.
Before you start
You need a working OpenAI Agents SDK agent. Decide the one output rule first, for example no prices in a reply, or no personal data in a reply. One rule per guardrail keeps the checker accurate.
Write the checker agent and attach it as an output guardrail
Create a small checker agent with a structured output type that answers whether the reply breaks the rule. Attach it to the main agent as an outputGuardrail. The checker reads the reply the main agent produced, not the user input, so its instructions should name the rule and give one example of a breaking reply.
Test with a reply that breaks the rule
Run the agent with a question that tempts it to break the rule, for example asking for a price when prices are banned from replies. Check the run halts before the reply is delivered. Then run a normal question and check the reply arrives.
Worked example: Output rule for a fictional shop agent
Maple Shop is a fictional online shop. Its agent must never state a price in a reply. The table shows the test.
| Question | Reply breaks the rule? | Delivered? |
|---|---|---|
| What is the delivery time? | No | Yes |
| How much is the city bike? | Yes, it would state a price | No, the guardrail stops it |
| Is the helmet in stock? | No | Yes |
Expected result (UNTESTED): the price question is stopped by the output guardrail, and the other two replies arrive. We checked the OpenAI Agents SDK API reference, which lists outputGuardrails on the Agent class, but we did not run the agent on this machine.
Limits
An output guardrail costs an extra model call on every reply, and a strict rule can block good replies too. Use output guardrails for rules that must never be broken, and test them with ten real replies before you trust them.
