Skip to main content
guardFunctionTool wraps a function tool definition (a name plus execute(input, context)) so authorize runs before execute. It does not import @openai/agents. tool() returns an object that exposes invoke, not execute, so guard the plain definition first and pass the result to tool(). For the throwing variant built on the policy engine, see OpenAI Agents SDK.

Runnable snippet

Denials

A refused call returns a ToolDenial object as the tool result, which the SDK serializes for the model:
Use formatDenial to return text instead:
agentId may be a function of the run context, the second argument of execute. requestApproval, action, resource and onDecision work as in the Vercel AI SDK helper. Use guardFunctionTools(definitions, options) for a list.

Python

The Python Agents SDK has the same guard, guard_function_tool from theauth.integrations. It wraps the FunctionTool that @function_tool returns. See LangGraph and CrewAI for the setup and a snippet.
Last modified on October 19, 2026