Summary

A tool use policy defines the boundaries within which a model can invoke tools. It tells the model which tools are available, when they should be used, when they must not be used, and how to handle failures gracefully.

How it works

  1. Categorize tools -- group tools by sensitivity and purpose (e.g., read-only, write, admin).
  2. Set policies per category -- define rules for each group: always allowed, requires confirmation, blocked.
  3. Define error behaviors -- specify what the model should do on timeout, auth failure, rate limit, or not-found.
  4. Evaluate and enforce -- at runtime, check each tool call against the policy before executing.

Policy categories

  • Always-allowed: Read-only queries, information retrieval, non-destructive operations.
  • Approval-required: Actions that modify state, send messages, or incur cost.
  • Context-dependent: Tools that should be used only when specific conditions are met.
  • Blocked: Tools that are never available to the model regardless of the situation.

Failure handling

  • Timeout: "The tool did not respond in time. Try a simpler approach or ask the user."
  • Auth error: "You do not have permission to use this tool. Suggest an alternative."
  • Rate limit: "This tool is rate-limited. Wait and retry, or use a different approach."
  • Not found: "The requested resource was not found. Verify the parameters or query."

Build This Pattern

Copy this prompt and paste it into Claude Code, OpenCode, Codex, or Cursor to implement this pattern.

Build me a tool use policy system. Architecture: define tool categories with allow/block/approval-required rules. Each tool has a policy: allowed parameters, rate limits, failure behavior. Error handling: tool failures should produce structured error types (timeout, auth, rate-limit, not-found) with fallback actions. Edge cases: handle tool conflict (two tools could answer), tool cascade (one tool output feeds another), and tool refusal. Best practices: log every tool invocation with caller, params, result, latency. Testing: verify policy enforcement for each tool category.