Skip to main content
An agent framework calls your tool functions whenever the model asks. Nothing in the framework checks that this agent may call this tool, or that a large payment needs a human first. guardTool and guardTools wrap a tool so theauth.policy.evaluate runs before execute. They import no framework and add no dependency: a tool is any object with an execute function.

The guard API

Both return the same type they were given. The wrapped tool is a new object made with a spread, so description, parameters, schemas and every other property carry over.

What happens on each decision

All three extend ToolGuardError. Their message is written for the model: it says what happened and tells it not to retry. Most frameworks send a thrown error’s message back to the model as the tool result, so you can let it propagate. Where a framework needs a returned string instead, catch ToolGuardError and return error.message. After a human approves, call the tool again with the approvalId option returning the approved request id. The guard passes it to evaluate, which spends it once: it must match the agent, action and resource, and a second use is denied with APPROVAL_ALREADY_USED.

Minimal example

Framework examples

The framework sections below show only shapes confirmed in each framework’s current documentation. Shape checked against the framework’s documented tool type; not run against the framework in this repo’s tests. The tests in this repo run the guard against the real in-memory engine with plain tool objects.

Vercel AI SDK

A full walkthrough with approvals and the decision record is on Vercel AI SDK. Shape checked against the framework’s documented tool type; not run against the framework in this repo’s tests. The AI SDK documents a tool as an object with description, inputSchema and execute, and you pass tools to generateText or streamText in a record keyed by name. guardTools takes that record and uses the keys as tool names. The second argument to execute is the framework’s call options, so use a fixed agentId or read it from your own closure.

OpenAI Agents SDK

A full walkthrough with approvals and the decision record is on OpenAI Agents SDK. Shape checked against the framework’s documented tool type; not run against the framework in this repo’s tests. The tool() helper documents name, description, parameters and execute. It returns a tool object that exposes invoke, not execute, so wrap the definition before you pass it to tool().
Pass errorFunction in the same options object as the guarded definition (checked against @openai/agents 0.20.0). It receives the context and the error and returns the text the model sees, so return error.message for a refusal. See OpenAI Agents SDK for a complete example.

LangGraph and LangChain

theAuth ships no LangGraph or CrewAI integration. The example below is a LangChain tool wrapped by hand, and CrewAI is not covered on this page. Shape checked against the framework’s documented tool type; not run against the framework in this repo’s tests. LangChain documents tool(fn, { name, description, schema }). The result is a tool object, not a plain one, so wrap the function and pass the guarded function to tool().
Last modified on October 17, 2026