Guardrails and Policy Enforcement for OpenAI Agents - How Traccia Proves Controls Fired
Guardrails for Your OpenAI Agent - But can you prove they were fleeing?
You built your agent using the OpenAI Agents SDK.
- β Input guardrail
- β Output Safety Nets
- β Calls to Tools
- β Multi Agent Handovers
Everything looks fine in development. But there are still two questions that matter in production: Did the guardrails actually run-and which ones fired? Can this agent still act when spend, error rate, or organization policy says it shouldn't?
Prompt text is direction. Production systems require proof and enforcement.
Two Layers. One instrumentation route.
| Layer | Purpose |
|---|---|
| Guardrail Detection | Classifies control on every run based on your traces. |
Policy Enforcement (@govern) |
Hard-blocks or pauses execution before a governed function is executed. |
These layers are complementary. Detection tells you what went on. **Governance decides what happens next.
Step 1 - One Time Instrument
from traccia import init
from agents import Agent, Runner, input_guardrail, GuardrailFunctionOutput
init() # OpenAI Agents SDK tracing starts automatically
@input_guardrail
async def scope_check(ctx, agent, input_data):
return GuardrailFunctionOutput(
output_info={"allowed": True},
tripwire_triggered=False,
)
agent = Agent(
name="Assistant",
instructions="Help the user with their request.",
input_guardrails=[scope_check],
)
result = await Runner.run(agent, user_message)
No extra wiring. Agent spans, guardrail spans, tool calls, latency, and LLM cost all feed into the same trace.
Step 2 - SDK Guardrails Turn Into Tier A Findings
Traccia auto-captures OpenAI Agents SDK Input & Output Guardrails.** No custom annotations. No hand-wrapping. Each trace consists of:
guardrail.summary.detected_categoriesguardrail.summary.triggered_categoriesguardrail.findings(structured findings for each guardrail span)
Step 3 - Guardrail Placement
For each trace and per agent you get aggregated:
- β Confidence in Coverage
- β Categories Activated
- β Absent Guardrails
Traccia automatically flags an agent with Input Guardrails but no Output Guardrail. Great for:
- Code Review
- Security Audit
- Responding to Incidents
- Production Monitoring
Step 4 - Enforce Side Effects with @govern
Guardrails fire and stop execution using tripwires. @govern checks if the next action is permitted prior to the function being run.
from traccia import init, govern
from traccia.governance import AgentBlockedError
init(api_key="...", endpoint="https://api.traccia.ai/v2/traces")
@govern(agent_id="my-agent", fail_open=False)
def run_side_effect(payload: dict) -> str:
return execute_action(payload)
try:
run_side_effect(payload)
except AgentBlockedError:
return "Agent blocked by policy."
Any operation that has real-world impact should be wrapped with:
- Sends to Database
- Removes
- External API Calls
- Payments
- Distribution of resources
- Anything that has permanent side effects
For critical actions, you should use: fail_open=False
Assembly Line
| Step | Check | Track |
|---|---|---|
| User Input | Input for Open Assistant SDK | Tier A Finding |
| Agent Execution | Tools + LLM | Full Trace + Cost |
| Final Output | OpenAI SDK Output Guardrail | Triggered Categories |
| --- | --- | --- |
| Side Effects | @govern + Platform Policy | Hard Block Before Execution |
The Bottom Line
β
Build Guardrails using the OpenAI Agents SDK
β
Show that they really shot with Traccia
β
Restrict the next allowed action of your agent with @govern
One init(). One trace stream. Transparency in every guardrail. Enforcement prior to every critical action. Thatβs what production AI systems need.
π Read More
- Comprehensive guide: https://traccia.ai/blog/openai-agents-guardrails-policy-enforcement
Comments
No comments yet. Start the discussion.