mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-17 09:34:48 +00:00
fix: escape unrecognized block types in errors
This commit is contained in:
parent
acf253ef7a
commit
a5ee60ec9e
2 changed files with 10 additions and 1 deletions
|
|
@ -591,7 +591,7 @@ class LiteLLMAnthropicMessagesAdapter:
|
|||
if isinstance(content, dict) and content.get("type") is not None
|
||||
}
|
||||
)
|
||||
type_list = ", ".join(unrecognized_block_types) or "unknown"
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -4890,6 +4890,15 @@ def test_translate_anthropic_to_openai_rejects_all_unrecognized_content_blocks()
|
|||
with pytest.raises(litellm.BadRequestError, match="not_a_real_block"):
|
||||
LiteLLMAnthropicMessagesAdapter().translate_anthropic_to_openai(request)
|
||||
|
||||
control_chars = {
|
||||
**request,
|
||||
"messages": [{"role": "user", "content": [{"type": "forged\nERROR: injected"}]}],
|
||||
}
|
||||
with pytest.raises(litellm.BadRequestError) as exc_info:
|
||||
LiteLLMAnthropicMessagesAdapter().translate_anthropic_to_openai(control_chars)
|
||||
assert "forged\\nERROR: injected" in str(exc_info.value)
|
||||
assert "forged\nERROR: injected" not in str(exc_info.value)
|
||||
|
||||
with_system = {
|
||||
**request,
|
||||
"messages": [
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue