Enforcing tool-call policy on Anthropic tool_use and tool_result blocks
Enforce policy at two points in the Anthropic tool-use loop: on the tool_use block before your application executes the call, and on the tool_result block before its content re-enters the conversation. Outbound checks cover the tool allowlist, arguments, caller authorization, rate and human approval. Inbound checks cover sensitive data and injected instructions. Run both in an execution component outside the model's context, fail closed, and record evidence for every decision.
Apply the policy at runtime in the execution path
- 1
1. Receive and correlate
Capture the tool_use block and tie its tool_use_id to the session, actor and agent.
- 2
2. Check the tool
Match the tool name and definition against the allowlist. Unknown tools fail closed.
- 3
3. Validate the call
Check input against the schema and value rules, then verify the actor's permissions for the target resource.
- 4
4. Decide
Return allow, block, rate limit, or escalate for human approval, and verify approval against the exact call.
- 5
5. Execute
Run the tool only after an allow decision, and capture its raw output.
- 6
6. Evaluate the result
Allow, redact or block the output, then return the tool_result with the matching tool_use_id.
Evidence an auditor expects for each decision
- Who and when: actor, agent, session and timestamp
- What: tool name, target resource and normalized parameters
- Decision: outcome, reason, action classification, risk score where used, and policy version
- Approval: approval identifier, approver, expiry, and whether it was consumed
- Execution: whether the tool ran and its execution result
- Result handling: what was allowed, redacted or blocked on the tool_result, tied by tool_use_id
Two enforcement points, two different risks
In the Anthropic Messages API tool-use pattern, the model does not run anything itself. It emits a tool_use block that names a tool and supplies input. Your application decides whether to execute it, then sends the output back in a tool_result block that refers to the originating call by its tool_use_id. Each hop is a separate enforcement surface.
The outbound surface is the proposed call. Unlike a traditional API client, the model decides which tool to invoke, when, and with what parameters, so the proposed call is untrusted input. The risks here are excessive permissions, unsafe arguments, and actions taken outside the scope of the user the session represents. OWASP's guidance on excessive agency calls for complete mediation, meaning every request to a downstream system is validated against security policy, and for running actions in the context of the specific user with minimum necessary privileges.
The inbound surface is the result. Once a tool executes, its return value is appended to the agent's context and becomes input to the next action, which may be another model call or another tool call. A compromised or malicious tool controls that return channel and can send adversarial content that works as indirect prompt injection. Tool output should be treated as untrusted external data, with the same caution applied to user-supplied input. Results can also carry sensitive data back into the conversation. MITRE ATLAS describes a tool and action guardrail mitigation that validates calls, arguments, permissions and outputs before execution or before results return to the model. That maps directly to these two points.
Define the policy for outbound tool_use blocks
Policy for the outbound call should be written as explicit conditions that an execution component can evaluate without consulting the model. Authorization belongs in that component, outside the agent's context. The model proposes, and the component independently validates scope, privilege and approval state.
Tool classification does not grant permission on its own. A tool marked read-only still requires a check that this actor may use it against this resource.
- Tool allowlist: Permit named tools with scoping such as read-only versus write and specific resources. Use separate tool sets for different trust levels. Unknown tools are denied.
- Argument constraints: Validate input against a strict JSON Schema with additionalProperties set to false and pattern constraints on strings. Add tool-specific value checks, such as permitted targets.
- Caller authorization: Check the call against the user's permissions and session context, not the agent's broader credentials.
- Rate limits: Cap call frequency per actor, session and tool so a looping or manipulated model cannot repeat a consequential action.
- Human approval: Require approval for consequential actions. Bind it to the actor and the exact call, with an expiry, and mark it consumed after use.
- Fail-closed default: If a tool has no policy entry or an approval requirement is missing, the decision is block.
Handle tool_result content as untrusted
Result policy answers a different question: what may return to the model? The decision outcomes are allow, redact and block. Redact when a result contains data the conversation should not hold, such as identifiers or confidential fields the user is not entitled to see. Block when content looks like instructions aimed at the model, or when the result fails an expected shape. A blocked result should be replaced with a controlled message so the loop can continue without the unsafe content.
Two cautions apply. First, labeling untrusted content in the prompt does not enforce a boundary. Keep untrusted content separate from trusted instructions, but do not rely on that separation as the control. Second, result inspection has limited coverage on its own, because detection of injected text is imperfect. It does not replace outbound checks. Any tool call that follows a result must be authorized and validated in code, independent of the model, exactly as if the result had never influenced it.
Result policy also limits downstream exposure. Missing scanning of tool outputs is a recognized risk because confidential information can leak through tool responses, logs and downstream integrations. Apply redaction before a result is stored or forwarded, not only before it reaches the model.
Edge cases: parallel calls, streaming and tool location
Parallel calls. When a response proposes more than one call, evaluate each independently. Each needs its own decision, its own approval where required, and its own rate-limit accounting. A denial on one call should not silently pass or cancel the others. Return a controlled result for each blocked call so the conversation stays consistent and the model can see the call did not run.
Streaming. If tool input arrives incrementally, treat partial input as incomplete. Assemble the full input, then validate and decide. Never begin execution on a fragment that has not passed schema and value checks.
Tool location. Enforcement in your execution path applies wherever your code runs the tool. For tools executed outside your application, you cannot interpose on the call itself, so the decision shifts to whether the tool is enabled at all and what data you allow it to reach. Keep an authoritative inventory of tools, capabilities, permissions and usage policies, because controls cannot be enforced against tools nobody has catalogued.
Tool definitions. Pin or hash the full definition, including schemas and annotations, and require review when it changes. This detects metadata changes only. Annotations such as a read-only hint are hints, not enforcement.
Two enforcement surfaces in the tool-use loop
Outbound: tool_use
Allowlist, argument constraints, caller authorization, rate limit, approval.
Execution
The tool runs only after an explicit allow decision.
Inbound: tool_result
Redact sensitive data, block injected instructions, then return to the model.
Evidence
Each decision recorded with actor, tool, parameters, outcome and policy version.
See enforcement on individual tool calls
Review how policy is enforced in the execution path and how audit-ready evidence is produced for each decision.
See How Evidence Is ProducedHow does your AI governance program compare?
See where your program has gaps in less than 2 minutes.