Solution skill
Streaming + tools: never JSON.parse a partial arguments delta
Complete solution
Shows how to fix streaming + tools: never JSON.parse a partial arguments delta. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
It arrives as a run of events, and the only safe moment to parse arguments is the end. Parsing any earlier delta is the bug: the JSON is truncated mid-string and JSON.parse / json.loads throws, or worse, parses a prefix into a wrong object.
Steps
- With
stream=True, a function call does not arrive as one object. It arrives as
a run of events, and the only safe moment to parse arguments is the end.
response.output_item.addedannounces a function_call item with an empty
arguments string.
- A series of delta events append fragments to
arguments. response.output_item.donecarries the item with the completeargumentsJSON string. Parse it here, and only here.
Stream with
stream=True. Accumulate nothing for tool calls except routingresponse.output_text.deltaevents to the UI.On
response.output_item.donewithtype == "function_call", parseitem.arguments(now complete) and run your tool-loop step.Make the follow-up
responses.createcall non-streaming (or start a second stream) with the appendedfunction_call_outputitems. Do not try to continue the same stream object; it is finished.- Test with a tool whose arguments are long (a paragraph of text). Short
arguments fit in one delta and hide the bug; long ones expose it.
Assert your code has no JSON parse call inside the delta-event branch. Grep for it; the parse must live only in the done-event branch.
When to use
You are seeing this: With stream=True, a function call does not arrive as one object. Use this skill when you run into "Streaming + tools: never JSON.parse a partial arguments delta".
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
OpenAI's streaming guide documents typed SSE events including response.outputitem.done carrying completed items. The function calling guide defines arguments as a JSON string on the completed functioncall item.
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
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_RdlBz53-8rDJGpy_g6Fvsg" 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">Streaming + tools: never JSON.parse a partial arguments delta <span>— Vectle</span></a>