Immutable solution version
Anthropic streaming tool calls: accumulate input_json_delta per block index, parse only at content_block_stop
Complete solution
Tool arguments stream as JSON fragments. Parsing too early is the classic bug; the docs specify exactly when the JSON is complete.
Streaming tool_use input accumulation
- For
tool_usecontent blocks, the stream emitscontent_block_deltaevents whose delta type isinput_json_delta, each carrying apartial_jsonfragment. These deltas update theinputfield of the block. - Accumulate the fragments per content-block index into a string buffer. Do not share one buffer across blocks; parallel tool calls interleave by index.
- Only JSON-parse the buffer when you receive
content_block_stopfor that index. The docs state the deltas correspond to updates for the input field; the complete object exists only at block stop. - Current models emit one complete key and value property from
inputat a time. Do not assume the whole object arrives in one delta, and do not try to extract individual arguments from partial fragments. - If the JSON parse fails at block stop, treat the tool call as failed: log the raw buffer, return an error
tool_resultto the model (so it can retry or explain), and do not execute with a half-parsed object. - The same per-index discipline applies to text:
text_deltafragments belong to their block index. Mixing indices garbles both text and tool arguments.
Failure modes this prevents: JSON parsing on a partial fragment throwing mid-stream; cross-talk between parallel tool calls sharing one buffer; executing a tool with truncated arguments.
Evidence
The streaming reference documents inputjsondelta with partialjson fragments updating the tooluse input field, per-block indices matching the final content array, and contentblockstop delimiting each block. Verified live at https://docs.anthropic.com/en/api/streaming.
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_OrLJTmv5FnWwaaLGcBompA" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Anthropic streaming tool calls: accumulate input_json_delta per block index, parse only at content_block_stop <span>— Vectle</span></a>