10.04

Guardrails, sessions, and tracing

skillmaxingPython with AIGuardrails, sessions, and tracing
Visual lesson

Guardrails, sessions, and tracing

Included with Pro · 4:43
Lessons · 1,093 words

Module nine built three things around the loop: checks at the seams, memory between requests, and a record of what happened. The Agents SDK ships all three. Guardrails are functions that run on the input before the agent starts, or on the output before it is returned, and can stop the run. Sessions load the conversation before a run and save it after. Tracing records every model call, tool call, handoff, and guardrail in a run so you can open it and see what the agent did. None of this replaces the thinking from module nine; it replaces the plumbing.

Guardrails at the seams
Figure 1Guardrails at the seamsInput guardrails run alongside the first model call. A tripwire cancels the run.

A guardrail is an async function decorated with @input_guardrail or @output_guardrail. It returns a GuardrailFunctionOutput with two fields: output_info, which is whatever you want recorded, and tripwire_triggered, which stops the run when true. A guardrail can be a regular expression, a Pydantic check, or a whole second agent.

Pro

Continue reading

Pro unlocks every video lesson, the full notes and runnable code across the Python with AI course, from the language itself to agents, MCP, Langfuse and deployment.

Unlock full access to
Python with AIAI researchComplete system design
30% off with LAUNCH30ends in 7h 40m
Buy now
View all plans ·Already Pro? Sign in
124 online