Assembling streamed input_json_delta fragments for a tool call

CCDV-F Applications & Integration Medium Question 19 of 105

A client streams the Messages API. When Claude calls a tool, the deltas carry a delta.type of input_json_delta whose partial_json slices arrive as fragments: first {"user_, then id": 4, then 2}.

How should the client assemble the tool input before executing the call?

Show answer and explanation

AConcatenate the slices per block index and parse at content_block_stop.

The slices are fragments of one serialized JSON string, so the client accumulates them per block index and parses the buffer once content_block_stop arrives for that block. Parsing a slice on its own throws immediately, since a fragment such as id": 4 is not valid JSON. A partial-JSON parser is a supported way to read incremental values, but firing the tool on its first complete object runs with arguments the model has not finished sending. A delta is not a key-and-value unit: the model emits one key and value at a time, then chunks it across deltas.

Source: platform.claude.com/docs/en/build-with-claude/streaming

Anonymous, no account needed. Your tally stays in this browser.

Next question Start 5 timed questions Browse all 105 original CCDV-F practice questions