fix(anthropic pass-through): report skipped block types

This commit is contained in:
DeepanshuPal 2026-09-18 22:44:52 +05:30
parent 33e13fafa2
commit acf253ef7a
2 changed files with 12 additions and 2 deletions

View file

@ -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",
)

View file

@ -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 = {