Guardrails
Input and output guardrails for AI agents: the SDK-native way, the framework-agnostic way, and what streaming and cancellation add.
Agents are useful because they act; they are risky for the same reason. A FAQ agent will happily answer questions it should refuse, and a helpful assistant will promise a deadline extension it cannot grant. Guardrails are the checks that run before the agent sees a request and before the user sees a response.
Two AISL workshops build the same safety flow from different angles, both around the DataTalks.Club Zoomcamp FAQ agent.
The OpenAI Agents SDK version
Guardrails for AI Agents with the OpenAI Agents SDK is the complete SDK walkthrough:
- Input guardrails block off-topic questions before the agent runs.
- Output guardrails catch policy problems — promising deadline extensions, writing homework for a student — before the response reaches the user.
- Tripwire handling turns a blocked run into a normal message.
- Multiple guardrails run in parallel; streaming changes when a block can still happen.
The framework-agnostic version
Build an Agent with
Guardrails
rebuilds the flow without leaning on SDK magic: the guardrail as a plain tool
plus an asyncio runner, so the same pattern works with any framework. The
async primer matters — guardrails only stay cheap if they run alongside the
agent, not in front of it.
The January workshop closes the loop on cancellation: when a guardrail trips, the wasted agent run is cancelled mid-flight instead of finishing and being thrown away.
Where they sit
Guardrails are one layer of agent quality. What to build next, and how to know the guardrails and the answers are any good: Evaluation and Monitoring.
Where to go next
- The agent being guarded: Agents
- The FAQ agent these workshops guard, deployed: Agent Deployment
Keep building with a membership
Every topic guide is free to read. Members get structured courses, live workshops, and feedback on real projects.