From 33e13fafa28853aabacf6c1ef769cca69f4701d3 Mon Sep 17 00:00:00 2001 From: Deepanshu Pal <40927968+DeepanshuPal@users.noreply.github.com> Date: Mon, 14 Sep 2026 22:21:22 +0530 Subject: [PATCH] fix: reject untranslated conversations with system messages --- .../adapters/transformation.py | 3 ++- ...erimental_pass_through_adapters_transformation.py | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py index 6a21efd7e48..e88cfffe684 100644 --- a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py +++ b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py @@ -580,7 +580,8 @@ class LiteLLMAnthropicMessagesAdapter: new_messages.append(assistant_message) has_conversational_input = any(m.get("role") != "system" for m in replayable_messages) - if has_conversational_input and len(new_messages) == 0: + has_translated_conversation = any(m.get("role") != "system" for m in new_messages) + if has_conversational_input and not has_translated_conversation: raise litellm.BadRequestError( message="Anthropic pass-through: every message's content blocks were of unrecognized types, so translation produced an empty conversation. Refusing to dispatch a request with no messages.", model=model, diff --git a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py index 7c71a5f7737..4687bcc5923 100644 --- a/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py +++ b/tests/test_litellm/llms/anthropic/experimental_pass_through/adapters/test_anthropic_experimental_pass_through_adapters_transformation.py @@ -4874,7 +4874,6 @@ def test_redacted_thinking_blocks_never_carry_cache_control(): def test_translate_anthropic_to_openai_rejects_all_unrecognized_content_blocks(): - """A request whose blocks are all unknown must not dispatch an empty conversation (#41091).""" import pytest import litellm @@ -4891,7 +4890,16 @@ def test_translate_anthropic_to_openai_rejects_all_unrecognized_content_blocks() with pytest.raises(litellm.BadRequestError): LiteLLMAnthropicMessagesAdapter().translate_anthropic_to_openai(request) - # A recognized block alongside an unrecognized one still translates normally. + with_system = { + **request, + "messages": [ + {"role": "system", "content": "keep this"}, + *request["messages"], + ], + } + with pytest.raises(litellm.BadRequestError): + LiteLLMAnthropicMessagesAdapter().translate_anthropic_to_openai(with_system) + mixed = { "model": "openai/gpt-4o", "max_tokens": 1024,