Ask before risky tools

Gate destructive tools with toolApproval and render the request.

AI SDK docsai-sdk.dev
Tool execution approval lets you require user confirmation before a server-side tool runs.
AI SDK UI · Chatbot Tool UsageRead docs ↗

From ai-sdk and the Tool Calling docs.

"Delete my latest file"

Press Send, then approve or deny in the Good pane.

Runs on its ownBad
    tools: { deleteFile }
    Needs approvalGood
      toolApproval: { deleteFile: 'user-approval' }
      // app/api/chat/route.ts
      const result = streamText({
        model: 'anthropic/claude-sonnet-5',
        messages: await convertToModelMessages(messages),
        tools: { deleteFile },
        toolApproval: { deleteFile: 'user-approval' },
      });
      
      // app/page.tsx
      const { messages, addToolApprovalResponse } = useChat({
        sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithApprovalResponses,
      });
      
      switch (part.state) {
        case 'approval-requested':
          return (
            <div key={part.toolCallId}>
              Delete {part.input.path}?
              <button onClick={() => addToolApprovalResponse({ id: part.approval.id, approved: true })}>Approve</button>
              <button onClick={() => addToolApprovalResponse({ id: part.approval.id, approved: false })}>Deny</button>
            </div>
          );
        case 'output-denied':
          return <p key={part.toolCallId}>Kept {part.input.path}.</p>;
      }

      Why it matters, pros and cons

      Why it matters

      The model picks the input. A wrong guess on a delete, a payment or an email can't be undone.

      Pros

      • The person sees the exact input before it runs.
      • The tool still runs on the server, with its secrets.
      • A denial goes back to the model, which can answer it.

      Cons

      • An extra click on every call: gate only what can't be undone.
      • Approval needs a second model call to resume.
      • needsApproval on the tool is deprecated in v7.