Initiates tool call
AI Models & Assistants / Knowledge library
Agent Guardrails
Checks or constrains inputs, outputs, and tool activity at defined workflow boundaries
Why learn Agent Guardrails?
They add deterministic or separately evaluated controls around probabilistic agent behavior.
The problem it solves
They block or flag unsafe, invalid, irrelevant, or policy-violating behavior before the wrong boundary is crossed.
Where it came from
Guardrails can validate initial input, final output, or individual tool calls. Their placement matters: an output check cannot undo an external side effect, and a parallel input check may finish after work has already started.
Build your understanding
Work through these exercises in order. Try the task before opening a reference.
- Define Agent Guardrails and identify its place in an agent architecture.
- Choose a task where Agent Guardrails improves an agent system.
- Diagnose one failure caused by misusing Agent Guardrails.
- Interpret a trace or state transition involving Agent Guardrails.
- Explain one operational tradeoff of Agent Guardrails.
Documentation and sources
- OpenAI Agents SDK: Guardrails (openai.github.io)
Connect the ideas
Explore next
Real World Example
Secure Financial Data Extraction
Financial institutions processing automated document analysis for client reports.
The business problem
Unintended exposure of sensitive PII or API keys within generated reports when agents interact with external data processing tools.
How this topic solves it
Implementing tool guardrails that intercept function-tool inputs and outputs to scan for patterns like secret keys or PII, blocking the execution or redacting the output before it reaches the end user.
- Define a tool_input_guardrail function to inspect tool arguments for sensitive patterns before execution.
- Define a tool_output_guardrail function to scan tool results for sensitive data after execution.
- Attach these guardrails to the specific FunctionTool instances used for document processing.
- Configure the agent to utilize these guarded tools, ensuring all data flows are validated at the tool boundary.
Shows how a tool guardrail intercepts data flow at the tool boundary.
Validates arguments
Executes logic
Redacts results
- Agent → invokes → Input Guardrail
- Input Guardrail → allows → Function Tool
- Function Tool → returns → Output Guardrail
Implementation example
This code maps to the Secure Financial Data Extraction scenario by intercepting tool arguments to prevent sensitive keys from being processed by the tool.
@tool_input_guardrail
def block_secrets(data):
# Inspect tool arguments for sensitive patterns
args = json.loads(data.context.tool_arguments or "{}")
if "sk-" in json.dumps(args):
return ToolGuardrailFunctionOutput.reject_content("Remove secrets.")
return ToolGuardrailFunctionOutput.allow()Expected business outcome
Automated prevention of data leakage, ensuring that sensitive information is never returned to the agent or the final user output.
Limitations and checks
Tool guardrails add latency to every tool invocation because they perform synchronous inspection; verify performance impact by monitoring the time taken for tool execution cycles.