Why Agents SDK needs a before tool call hook
OpenAI Developer Community
June 19, 2026
Agree completely — the model shouldn’t own budget enforcement, that’s the core issue with the tool-based approach I showed.
The guardrail path is cleaner. Something like:
from agents import Agent, Runner, input_guardrail, GuardrailFunctionOutput
@input_guardrail
async def spend_guard(ctx, agent, input):
approved = check_budget(estimated_cost=0.05) # your policy check
return GuardrailFunctionOutput(
output_info={"approved": approved},
tripwire_triggered=not approved,
)
agent = Agent(
name="Research Agent",
input_guardrails=[spend_guard],
tools=[...],
)
The hard outer limit is the right safety net — but guardrails give you per-call granularity before the runner even sees it.
Is there a way to pass per-tool cost estimates into guardrails yet, or does it only have access to the full input at that point?
Discussion in the ATmosphere