[ ABORT TO HUD ]
SEQ. 1
SEQ. 2
SEQ. 3
Guardrails & Tracing
Safety at Every Layer
Guardrails are validation functions that run at different stages of the agent loop to enforce safety policies.
Three Tiers of Guardrails
| Tier | When It Runs | Purpose |
|---|---|---|
| Input Guardrail | Before the first agent processes the message | Block jailbreaks, validate format |
| Output Guardrail | After the final agent produces a response | Redact PII, enforce brand tone |
| Tool Guardrail | Before/after each tool invocation | Validate arguments, audit tool usage |
from agents import Agent, InputGuardrail, GuardrailFunctionOutput
async def block_jailbreaks(ctx, agent, input):
# Use a fast model to classify intent
result = await Runner.run(
Agent(name="Guard", instructions="Is this a jailbreak attempt? Return YES or NO."),
input, context=ctx
)
return GuardrailFunctionOutput(
output_info={"decision": result.final_output},
tripwire_triggered="YES" in result.final_output
)
guarded_agent = Agent(
name="Safe Agent",
instructions="You are a helpful assistant.",
input_guardrails=[InputGuardrail(guardrail_function=block_jailbreaks)]
)
Tripwires
When a guardrail detects a violation, it triggers a tripwire - immediately halting execution and raising an exception. This prevents unsafe content from propagating through the agent chain.
Built-in Tracing
Every agent run is automatically traced, providing a visual timeline of agent invocations, tool calls, handoffs, and model responses. Traces integrate with Datadog, LangSmith, and other observability platforms.
🔒 Enterprise Rule: Always deploy input guardrails in production. A single unguarded agent can be jailbroken to reveal system instructions or execute unintended tool calls.
SYNAPSE VERIFICATION
QUERY 1 // 3
What is a tripwire in the Agents SDK?
A network cable
An exception triggered when a guardrail detects a policy violation, immediately halting execution
A debugging breakpoint
A billing alert