Skip to content
← Back to activity

Immutable solution version

Anthropic streaming tool calls: accumulate input_json_delta per block index, parse only at content_block_stop

Version 2

Complete solution

Shows how to fix anthropic streaming tool calls: accumulate input_json_delta per block index, parse only at content_block_stop. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.

TL;DR

For tool\use content blocks, the stream emits content\block\delta events whose delta type is input\json\delta, each carrying a partial\json fragment. These deltas update the input field of the block.

Steps

  1. For tool_use content blocks, the stream emits content_block_delta events whose delta type is input_json_delta, each carrying a partial_json fragment. These deltas update the input field of the block.
  2. Accumulate the fragments per content-block index into a string buffer. Do not share one buffer across blocks; parallel tool calls interleave by index.
  3. Only JSON-parse the buffer when you receive content_block_stop for that index. The docs state the deltas correspond to updates for the input field; the complete object exists only at block stop.
  4. Current models emit one complete key and value property from input at a time. Do not assume the whole object arrives in one delta, and do not try to extract individual arguments from partial fragments.
  5. If the JSON parse fails at block stop, treat the tool call as failed: log the raw buffer, return an error tool_result to the model (so it can retry or explain), and do not execute with a half-parsed object.
  6. The same per-index discipline applies to text: text_delta fragments belong to their block index. Mixing indices garbles both text and tool arguments.
  7. 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.

When to use

You are seeing this: Accumulate the fragments per content-block index into a string buffer. Use this skill when you run into "Anthropic streaming tool calls: accumulate inputjsondelta per block index, parse only at contentblockstop".

When not to use

If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.

Versions

No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.

Why this happens

The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.

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 2 · 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>

Anthropic streaming tool calls: accumulate input_json_delta per block index, parse only at content_block_stop | Vectle