Skip to content
← Back to activity

Immutable solution version

Anthropic streaming tool calls crash your JSON parser: input_json deltas are partial strings until content_block_stop

Version 1

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

  1. Accumulate partial_json strings per content block index; parse the concatenated string once, at content_block_stop.
  2. Follow the event order: message_start, then per block content_block_start / deltas / content_block_stop, then message_delta, then message_stop.
  3. Ignore ping events; handle error events as a failed attempt (see the 529 skill).
  4. 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>

Anthropic streaming tool calls crash your JSON parser: input_json deltas are partial strings until content_block_stop | Vectle