mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-17 09:34:48 +00:00
fix: reject untranslated conversations with system messages
This commit is contained in:
parent
eab82b6f35
commit
33e13fafa2
2 changed files with 12 additions and 3 deletions
|
|
@ -580,7 +580,8 @@ class LiteLLMAnthropicMessagesAdapter:
|
|||
new_messages.append(assistant_message)
|
||||
|
||||
has_conversational_input = any(m.get("role") != "system" for m in replayable_messages)
|
||||
if has_conversational_input and len(new_messages) == 0:
|
||||
has_translated_conversation = any(m.get("role") != "system" for m in new_messages)
|
||||
if has_conversational_input and not has_translated_conversation:
|
||||
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.",
|
||||
model=model,
|
||||
|
|
|
|||
|
|
@ -4874,7 +4874,6 @@ def test_redacted_thinking_blocks_never_carry_cache_control():
|
|||
|
||||
|
||||
def test_translate_anthropic_to_openai_rejects_all_unrecognized_content_blocks():
|
||||
"""A request whose blocks are all unknown must not dispatch an empty conversation (#41091)."""
|
||||
import pytest
|
||||
|
||||
import litellm
|
||||
|
|
@ -4891,7 +4890,16 @@ def test_translate_anthropic_to_openai_rejects_all_unrecognized_content_blocks()
|
|||
with pytest.raises(litellm.BadRequestError):
|
||||
LiteLLMAnthropicMessagesAdapter().translate_anthropic_to_openai(request)
|
||||
|
||||
# A recognized block alongside an unrecognized one still translates normally.
|
||||
with_system = {
|
||||
**request,
|
||||
"messages": [
|
||||
{"role": "system", "content": "keep this"},
|
||||
*request["messages"],
|
||||
],
|
||||
}
|
||||
with pytest.raises(litellm.BadRequestError):
|
||||
LiteLLMAnthropicMessagesAdapter().translate_anthropic_to_openai(with_system)
|
||||
|
||||
mixed = {
|
||||
"model": "openai/gpt-4o",
|
||||
"max_tokens": 1024,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue