Anthropic Tool Use ID Correlation Needs an Exact Result Join
Anthropic returns a unique id on each client tool_use block and requires the matching tool_result to copy that value into tool_use_id. Production agents should preserve the provider identifier across queues, parallel calls, failures, and follow-up Messages requests while keeping application execution IDs and target idempotency keys separate. This guide defines the join, state ledger, rejection cases, and routed HTTP evidence.

An Anthropic client tool call returns a tool_use content block with an id. The application runs the named tool, then sends a tool_result block whose tool_use_id copies that exact value. One assistant response can contain several tool calls, so position, tool name, and completion order are unsafe joins. The provider ID is the stable link between each proposal and the result returned to Claude.
I want that link preserved for its documented job. Execution, authorization, retries, and downstream effects need application-owned evidence beside the Anthropic identifier.
TL;DR
- Copy each
tool_use.idexactly into the matchingtool_result.tool_use_id. - Create one pending-call row per tool block before dispatching work to a queue.
- Keep Anthropic IDs, application execution IDs, gateway decision IDs, and target idempotency keys separate.
- Reject orphaned, duplicated, mismatched, late, and already-consumed result IDs before the next provider request.
The ID joins one proposal to one result
Anthropic's tool-call handling guide says every client tool_use block carries a unique id for that particular block. The later tool_result uses tool_use_id equal to that id. Preserve the provider value as received. Never rebuild it from a message ID, tool name, array index, or local job number.
When the model response arrives, create one pending row for every tool block. Store the Anthropic message ID, content-block index, tool-use ID, tool name, input digest, model route, and observation time. The row records what Claude proposed. It should exist before application workers begin execution, because a crash after queue dispatch can otherwise leave an action with no durable proposal record.
The AI response tool-call validation guide owns schema and argument checks before execution. Correlation starts after the block is recognized and keeps that validated object attached to its eventual result.
Parallel calls rule out positional joins
One assistant turn can request several tools. Anthropic instructs clients to return one tool_result for each tool_use block, including failed calls. Workers may finish in a different order from the response array. A fast account lookup can complete while a slower document search is still running, even when document search appeared first.
Join by exact tool-use ID inside the conversation or workflow scope. Use a uniqueness constraint so a duplicate provider ID in one assistant response enters quarantine before any dispatch. Pairing by index fails after asynchronous execution, while a tool-name join becomes ambiguous when Claude calls the same tool twice with different inputs.
A useful ledger separates states such as observed, validated, authorized, dispatched, succeeded, failed, result_ready, and result_submitted. Each transition needs a timestamp and actor. A whiteboard with three arrows crossing between identical lookup_customer boxes is the concrete warning: once the jobs finish out of order, only the IDs tell you which result belongs on each arrow.
The agentic AI audit trail provides the broader run-level record around this per-call join.
Provider correlation and execution evidence differ
A valid tool-use ID proves which Anthropic proposal a result answers. It says nothing about application authorization or downstream completion. Give each execution attempt its own ID and record authenticated identity, policy version, target, argument digest, start time, terminal outcome, and result digest.
Keep these fields separate:
anthropic_message_ididentifies the assistant message.anthropic_tool_use_ididentifies one provider tool block.gateway_decision_ididentifies the routed policy decision.execution_attempt_ididentifies one application invocation attempt.target_idempotency_keybelongs to the downstream operation's replay contract.
My blunt opinion is that a single database column named tool_call_id is an incident waiting to happen. Nobody can tell which system minted it or which lifecycle it controls.
For payments, deletions, and notifications, the target system still needs an idempotency contract. Reusing an Anthropic ID as a label may aid lookup, but provider correlation alone supplies no exactly-once guarantee.
The follow-up request has strict structure
The same official guide requires the earlier assistant content to be kept unchanged in message history. The next user message carries one tool_result for each client tool call. Those result blocks must immediately follow the assistant tool-use message, and they must appear first in the user content array. Text can follow only under the documented conditions. The Messages API reference defines tool_use_id on the result block as a string field in the request content schema.
Validate the follow-up body before it reaches POST /v1/messages. Every tool_use_id should resolve to one pending block in the preceding assistant content. Every required pending block should have one result, including failures marked with is_error: true. Reject an ID belonging to another conversation, an unknown ID, a duplicate result, a result submitted after terminal consumption, or intervening message history that breaks adjacency.
Quietly choosing the nearest tool name corrupts the join. Preserve the malformed request digest and return a stable local error. Anthropic documents errors such as tool-use IDs lacking immediate result blocks, so local validation saves a provider exchange and produces a clearer policy record.
The Anthropic API gateway pattern shows where that request-body validation sits in the routed Messages flow.
Retries need explicit replay states
A transport failure after tool execution creates an ambiguous branch. The tool may have succeeded while the worker missed the response. Retrying the local action requires the target idempotency rule. Repeating the model call can mint another Anthropic tool-use ID and another proposal.
Persist the first execution attempt before invoking the target. On a retry, attach another attempt row to the same pending provider call. When the target outcome is known, create one result payload and mark it ready. Submitting that payload to Claude is another state transition with its own Messages request and gateway decision.
If the follow-up provider request times out, reconcile its request state before rebuilding the entire tool loop. A second submission of the same result may be acceptable to the API only under behavior the application has tested and documented. Preserve both transport attempts rather than overwriting the first.
A model retry that generates a new assistant response can produce a new tool-use ID for a semantically similar action. Treat it as a new proposal and run authorization again. Similar arguments do not merge provider identities.
Routed evidence should reconstruct both Messages calls
The first HTTP exchange contains the tool catalog and returns the assistant tool_use block. Application code then acts locally or through another service. The second Messages request carries the assistant content plus the matching tool_result. A routed audit needs to connect the two model exchanges while leaving local execution claims to the application ledger.
Record the authenticated caller context, conversation or operation ID, Anthropic message ID, tool-use ID, tool name, input digest, result digest, policy version, and allow or deny outcome. Sensitive tool inputs and results can remain in a protected application store under route-specific retention, with digests in the correlation index.
The AI audit log schema supplies common identity and policy fields. Add typed Anthropic fields instead of squeezing them into a generic request_id.
If the tool itself makes a separately authenticated HTTP call through an enforcement point, write another decision record for that exchange. Local process calls and bypass traffic remain outside the model proxy's evidence.
A destructive fixture should scramble completion order
Return one assistant message containing three client tool_use blocks, including two calls to the same tool with different inputs. Complete the workers in reverse order. The collector should build three results with exact IDs and submit all required result blocks first in the following user message.
Then submit an unknown ID and a duplicate. Follow those cases with an ID copied from another conversation, an omitted failed-tool result, text before the result blocks, and an intervening user message. Every malformed case should fail before Anthropic dispatch with a stable reason and retained request digest.
Crash a worker after the target commits but before its response reaches the application. Verify that retry uses the target idempotency contract and adds an execution attempt under the original tool-use row. Next, drop the connection during the follow-up Messages request and prove the model-transport attempt remains separate from tool execution.
The final trace should start from any one tool-use ID and reveal its proposal, authorization, execution attempts, result, submission request, and Anthropic response.
DeepInspect
DeepInspect can preserve and validate Anthropic tool-use identifiers on authenticated user or agent Messages traffic deliberately routed through its HTTP proxy. It can record the model response block, reject orphaned or mismatched result IDs on the follow-up request, evaluate the routed tool name and content under policy, and link both model exchanges through per-decision records.
The application owns local tool authorization, execution, retries, queues, target idempotency, and proof of downstream effects. DeepInspect can join its HTTP evidence to those application records without claiming visibility into activity that never crossed the proxy.
Book a technical deep dive at deepinspect.ai.
Frequently asked questions
- Is tool_use.id the same as the Anthropic message ID?
No. The message ID identifies the assistant message. Each
tool_useblock inside its content has its ownid, which the application copies intotool_result.tool_use_id. Preserve both as typed fields.- Can results be matched by array position?
Position is useful provenance but unsafe as the operational join. Parallel workers finish out of order, and one response can call the same tool more than once. Match every result by exact tool-use ID within the correct workflow scope.
- Does a matching tool_use_id prove the tool executed?
It proves the provider-side proposal-to-result correlation. Execution needs an application record with authorization, target, attempts, timestamps, and outcome. A denied call can retain a valid tool-use ID while producing no downstream invocation.
- What should happen when a tool fails?
Return a
tool_resultfor that tool-use ID and setis_errorto true, following Anthropic's documented format. Keep the application failure detail under its approved retention policy and send Claude only the result content needed to continue safely.