[ ABORT TO HUD ]
SEQ. 1
SEQ. 2
SEQ. 3

Guardrails & Tracing

🤖 The Agents SDK 15 min 300 BASE XP

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

TierWhen It RunsPurpose
Input GuardrailBefore the first agent processes the messageBlock jailbreaks, validate format
Output GuardrailAfter the final agent produces a responseRedact PII, enforce brand tone
Tool GuardrailBefore/after each tool invocationValidate 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
Watch: 139x Rust Speedup
Guardrails & Tracing | The Agents SDK — OpenAI Academy