From 573f678690958170dc472aa75faaf469b202a097 Mon Sep 17 00:00:00 2001 From: rudra717 <52209277+rudra717@users.noreply.github.com> Date: Mon, 6 Apr 2026 10:03:34 -0700 Subject: [PATCH] fix(anthropic): don't drop text_delta when backend sends empty tool_calls Some OpenAI-compatible backends (e.g. mlx_lm.server) always populate tool_calls:[] in every streaming delta, even for plain-text responses. The check `if choice.delta.tool_calls is not None` treats an empty list as truthy, entering the tool_calls branch and overwriting partial_json to "", which drops the actual text content. Add a length check so empty tool_calls lists are ignored, allowing text_delta events to flow through correctly. Fixes BerriAI/litellm#25172 Co-Authored-By: Claude --- .../experimental_pass_through/adapters/transformation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py index ed49943b7fe..133bc6b11e7 100644 --- a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py +++ b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py @@ -1418,7 +1418,7 @@ class LiteLLMAnthropicMessagesAdapter: for choice in choices: if choice.delta.content is not None and len(choice.delta.content) > 0: text += choice.delta.content - if choice.delta.tool_calls is not None: + if choice.delta.tool_calls is not None and len(choice.delta.tool_calls) > 0: partial_json = "" for tool in choice.delta.tool_calls: if (