Skip to main content

Guardrails & Tracing — The Agents SDK

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

Guardrails & Tracing

🤖 The Agents SDK 15 min 300 BASE XP⌨ HANDS-ON LAB

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.
⌨ HANDS-ON LABEnable OpenTelemetry Tracing for Agents
⭐ +150 XP

Track every LLM call and tool invocation in multi-agent workflows. Enable OpenAI tracing in your shell environment.

1Verify built-in tracing is active by default (ensure OPENAI_AGENTS_DISABLE_TRACING=0).
lab-sandbox — simulated environment
INFINITY LAB SANDBOX v2.6 — simulated shell
Type the command for the current objective. Helpers: "hint", "solution", "clear".
$
OBJECTIVE 1 / 1 — type "hint" if stuck
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