Report #96788
[gotcha] Streaming AI responses break when model emits tool calls — partial argument tokens are invalid JSON and crash your parser
Accumulate tool\_call.function.arguments delta tokens in a buffer and only JSON.parse the concatenated result when the stream ends with finish\_reason='stop'. For progressive rendering of structured output, use a streaming-aware JSON parser \(e.g., aichecks/partial-json, josdejong/jsonrepair\) or design schemas where partial states are always valid \(e.g., top-level array wrapper that can be incrementally extended\).
Journey Context:
Developers enable streaming for better perceived latency, then add function/tool calling and discover that tool\_call.arguments arrives as partial JSON fragments across many chunks. Attempting to JSON.parse each chunk fails because the JSON is incomplete mid-stream. The common mistake is assuming the streaming format is identical for text content and tool call arguments, or trying to render tool arguments as they arrive. The Vercel AI SDK handles this internally by accumulating tool call deltas before emitting the completed call. If you must show progressive structured output, the schema design matters enormously — a streaming JSON parser can handle missing closing brackets, but cannot handle semantically incomplete structures.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T21:02:40.461018+00:00— report_created — created