diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py index e88cfffe684..3e1fd097074 100644 --- a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py +++ b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py @@ -582,8 +582,18 @@ class LiteLLMAnthropicMessagesAdapter: has_conversational_input = any(m.get("role") != "system" for m in replayable_messages) has_translated_conversation = any(m.get("role") != "system" for m in new_messages) if has_conversational_input and not has_translated_conversation: + unrecognized_block_types = sorted( + { + str(content.get("type")) + for message in replayable_messages + if message.get("role") != "system" and isinstance(message.get("content"), list) + for content in message["content"] + if isinstance(content, dict) and content.get("type") is not None + } + ) + type_list = ", ".join(unrecognized_block_types) or "unknown" 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.", + message=f"Anthropic pass-through: every message's content blocks were of unrecognized types ({type_list}), so translation produced an empty conversation. Refusing to dispatch a request with no messages.", model=model, llm_provider="anthropic", ) 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 4687bcc5923..bb205762dab 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 @@ -4887,7 +4887,7 @@ def test_translate_anthropic_to_openai_rejects_all_unrecognized_content_blocks() "messages": [{"role": "user", "content": [{"type": "not_a_real_block", "text": "hello"}]}], } - with pytest.raises(litellm.BadRequestError): + with pytest.raises(litellm.BadRequestError, match="not_a_real_block"): LiteLLMAnthropicMessagesAdapter().translate_anthropic_to_openai(request) with_system = {