From 47a8d4b080bfdeb041015e54532c28229ef656ca Mon Sep 17 00:00:00 2001 From: Kiyeon Jeon Date: Mon, 13 Apr 2026 05:02:34 +0900 Subject: [PATCH] fix(streaming): skip empty partial_json in trigger chunk delta Only emit the trigger chunk's input_json_delta when partial_json is non-empty. OpenAI-style providers send arguments="" in the first tool chunk, which was producing a spurious empty content_block_delta event and breaking existing test expectations. --- .../adapters/streaming_iterator.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py b/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py index 05cf0d9a4ae..1c1bfc1b327 100644 --- a/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py +++ b/litellm/llms/anthropic/experimental_pass_through/adapters/streaming_iterator.py @@ -144,9 +144,12 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): ) # Also emit the trigger chunk's delta so that providers like # Ollama that send the complete tool call in a single chunk - # do not lose their arguments. + # do not lose their tool arguments. Skip empty deltas + # (e.g. OpenAI sends arguments="" in the first tool chunk). if processed_chunk.get("type") == "content_block_delta": - self.chunk_queue.append(processed_chunk) + delta = processed_chunk.get("delta", {}) + if delta.get("partial_json"): + self.chunk_queue.append(processed_chunk) self.sent_content_block_finish = False return self.chunk_queue.popleft() @@ -328,9 +331,13 @@ class AnthropicStreamWrapper(AdapterCompletionStreamWrapper): # Also emit the trigger chunk's delta so that providers # like Ollama that send the complete tool call in a - # single chunk do not lose their arguments. + # single chunk do not lose their tool arguments. Skip + # empty deltas (e.g. OpenAI sends arguments="" in the + # first tool chunk). if processed_chunk.get("type") == "content_block_delta": - self.chunk_queue.append(processed_chunk) + delta = processed_chunk.get("delta", {}) + if delta.get("partial_json"): + self.chunk_queue.append(processed_chunk) # Reset state for new block self.sent_content_block_finish = False