mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-11 03:38:38 +00:00
fix(anthropic): reject requests whose content blocks are all unrecognized
This commit is contained in:
parent
615ed7900f
commit
93324d1ec5
1 changed files with 20 additions and 1 deletions
|
|
@ -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,
|
||||
)
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue