diff --git a/litellm/llms/anthropic/pass_through/adapters/transformation.py b/litellm/llms/anthropic/pass_through/adapters/transformation.py index 022bc6337b5..4ad30bdcb92 100644 --- a/litellm/llms/anthropic/pass_through/adapters/transformation.py +++ b/litellm/llms/anthropic/pass_through/adapters/transformation.py @@ -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, - ) + )