Skip to main content
guardAiSdkTools takes the tool map you pass to generateText or streamText and returns a copy where every execute calls authorize first. It has no runtime dependency on ai: the tool type is structural. A refused call does not throw. It resolves to a ToolDenial with the decision code, so the model reads the refusal as the tool result and stops. For the throwing variant built on the policy engine, see Vercel AI SDK.

Runnable snippet

Pass tools to generateText({ model, tools, prompt }) as usual.

Options

If authorize throws, the call is refused with code guard_error. The guard fails closed.

Approval

The approved id is spent on a single retry. If the function returns undefined, the model gets a denial with approvalRequired: true.
Last modified on October 19, 2026