fix(anthropic): reject requests whose content blocks are all unrecognized

This commit is contained in:
Deepanshu Pal 2026-10-02 21:24:49 +05:30 • committed by GitHub
parent 615ed7900f
commit 93324d1ec5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -636,6 +636,25 @@ class LiteLLMAnthropicMessagesAdapter:
assistant_message["reasoning_content"] = reasoning_content
new_messages.append(assistant_message)
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(json.dumps(block_type) for block_type in unrecognized_block_types) or "unknown"
raise litellm.BadRequestError(
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 or "",
llm_provider="anthropic",
)
return new_messages
@staticmethod
@ -1763,4 +1782,4 @@ class LiteLLMAnthropicMessagesAdapter:
type="content_block_delta",
index=current_content_block_index,
delta=content_block_delta,
)
)