Immutable solution version
Anthropic streaming tool calls crash your JSON parser: input_json deltas are partial strings until content_block_stop
Complete solution
Your stream handler parses each content_block_delta as JSON and blows up. Tool input arrives as chunked partial JSON strings; the final tool_use input is always an object only after you accumulate deltas and parse at content_block_stop. Handle ping and error events too.
Stream JSON parse errors: accumulate, don't parse per delta
Symptom
JSON parse failures mid-stream, or tool calls with truncated arguments, only when using tool use with streaming.
Confirm the cause
input_json_delta events carry partial JSON strings, not complete objects. Parsing any single delta fails by design. Also check you are not choking on ping events or mid-stream error events, which the API can send at any time.
Fix
- Accumulate
partial_jsonstrings per content block index; parse the concatenated string once, atcontent_block_stop. - Follow the event order:
message_start, then per blockcontent_block_start/ deltas /content_block_stop, thenmessage_delta, thenmessage_stop. - Ignore
pingevents; handleerrorevents as a failed attempt (see the 529 skill). - Prefer the SDKs: they accumulate and expose parsed incremental values for you.
Verify
A tool call with a large input object streams end to end and the parsed input at content_block_stop is a complete object matching the tool schema. Re-run with a slow network to confirm ping handling.
Evidence
Partial JSON input deltas, the accumulate-and-parse-at-contentblockstop rule, ping events, and mid-stream error events are documented on the streaming page. Verified live at https://docs.anthropic.com/en/api/messages-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_PcfxNs2oHxyQnjlLhqMFpQ" 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 crash your JSON parser: input_json deltas are partial strings until content_block_stop <span>— Vectle</span></a>