[BUG] Streaming tool-use arguments truncated by premature stop termination, producing invalid JSON

Resolved 💬 4 comments Opened Jan 19, 2026 by longxaing Closed Feb 27, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When using the streaming API with native tool use enabled, we intermittently observe the stream terminating with a stop finish/termination signal before all tool argument chunks have been delivered. As a result, the accumulated tool_use/tool-call arguments buffer is truncated and cannot be parsed as valid JSON. After concatenating the collected chunks,

the resulting message is:{'role': 'assistant', 'content': [{'type': 'text', 'text': '\u73b0\u5728\u6211\u5c06\u521b\u5efa\u7b2c\u4e00\u6279\u5e7b\u706f\u7247\uff081-4\u9875\uff09\uff1a', 'cache_control': {'type': 'ephemeral'}}], 'tool_calls': [{'id': 'toolu_01HM8nkFtR9Ggf2hidKL1zrS', 'type': 'function', 'function': {'name': 'create_batch_slides', 'arguments': '{"file_path_list": ["presentation/\u660e\u671d\u4ecb\u7ecd/01.html","presentation/\u660e\u671d\u4ecb\u7ecd/02.html","presentation/\u660e\u671d\u4ecb\u7ecd/03.html","presentation/\u660e\u671d\u4ecb\u7ecd/04.html"]'}}]}, and it is an invalid json, last chunk is [INFO]

Received chunk:

ModelResponseStream(id=‘chatcmpl-7b2d912a-3e20-497c-859b-4764c51f0d89’, created=1768442197, model=‘dev-anthropic-claude-sonnet-4-0’, object=‘chat.completion.chunk’, system_fingerprint=None, choices=[StreamingChoices(finish_reason=‘stop’, index=0, delta=Delta(provider_specific_fields=None, content=None, role=None, function_call=None, tool_calls=None, audio=None), logprobs=None)], provider_specific_fields=None), serialized: {“id”:“chatcmpl-7b2d912a-3e20-497c-859b-4764c51f0d89”," created“:1768442197,”model“:”dev-anthropic-claude-sonnet-4-0“,”object“:”chat.completion.chunk“,”system_fingerprint“:null,”choices“:[{”finish_reason“:”stop“,‘index’:0,” delta“:{”provider_specific_fields“:null,”content“:null,”role“:null,”function_call“:null,”tool_calls“:null,”audio“:null},‘logprobs’:null}],”provider_specific_fields":null}, Thread id is c187ac76-6ec0-4999-b207-ef6e3d3bbc7f path=/internal/run-agent request_id=5766fe69 correlation_id=a6f9ad984c6f4fd68cda8f731e30aa95.1 user_id=dac3e7bf -f322-4f07-a9a8-6539e3a06c53@72f988bf-86f1-41af-91ab-2d7cd011db47 agent_run_id=52a660ec-5b75-4439 -b3e1-4a6ab4c0c4e7 session_id=8d51bd7c13b90132 tenant_id=72f988bf -86f1-41af-91ab-2d7cd011db47 trace_id=7700e600da9aaa52f6e9e9d76f95b569 span_id=ff78947025ca8924

What Should Happen?

While the model is emitting a tool call (tool use) over streaming, it should:

Stream all tool argument deltas/chunks until the tool arguments form a complete, valid JSON payload; and
Only then emit a final termination/finish signal for the tool call (or an explicit tool-use completion signal).

In particular, the stream should not emit a terminal stop while tool arguments are still incomplete.

Error Messages/Logs

Steps to Reproduce

litellm version is: 1.80.15
claude is claude-sonnet-4-0

Claude Model

None

Is this a regression?

Yes, this worked in a previous version

Last Working Version

_No response_

Claude Code Version

claude-sonnet-4-20250514

Platform

Anthropic API

Operating System

Other Linux

Terminal/Shell

Windows Terminal

Additional Information

_No response_

View original on GitHub ↗

This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗