An input guardrail checks the request before the agent does any work, and a tripwire stops the run when it fires. In the OpenAI Agents SDK an input guardrail returns whether the tripwire is triggered, and a triggered tripwire throws and stops the run. Put the guardrail on the first agent in the chain, because input guardrails only run for the first agent. Keep the rule to one check, such as the request must be about the product, so a blocked request tells you exactly why it was blocked.
What you need
- An agent with a defined topic, for example product support only
- One rule for what is disallowed, written in one sentence
- Three test requests: two on-topic and one off-topic
Step 1: Write the guardrail as one check
Write the guardrail to return whether the request is off-topic, with a short reason. A guardrail that checks five things at once gives a useless reason when it fires.
Step 2: Attach it to the first agent and make it blocking
Attach the input guardrail to the first agent and set it to run before the agent starts, so a blocked request never reaches the model or any tool.
Step 3: Run the three test requests
Run the two on-topic requests and confirm they pass, then the off-topic one and confirm it is blocked with the reason. If an on-topic request is blocked, the rule is too broad.
Worked example: synthetic guardrail check
The table below is a synthetic example. It shows the expected result of the guardrail; no agent was run.
| Request | Blocked? | Result |
|---|---|---|
| How do I reset my password? | No | Pass |
| What is the refund window? | No | Pass |
| Write me a poem about the sea | Yes | Pass |
| Blocked request gives a reason | Yes | Pass |
Expected result (UNTESTED). the two support questions pass and the poem request is blocked with a reason, before any tool runs. This check was not run live; the table shows the expected result for the synthetic example.
Limits
- An input guardrail only runs on the first agent in the chain, so later agents are not checked.
- A guardrail judged by a model can pass requests a strict function would block.
- A rule that is too broad blocks good requests, so test with on-topic edge cases.
- A blocked request still costs the guardrail check, so keep the check cheap.
