BerriAI/litellm · error · AnthropicError
{e} Received Messages={messages}
Error message
{e}
Received Messages={messages} What it means
Anthropic request transform error wrapper: while transforming OpenAI messages to Anthropic format (system extraction, tool name rewriting, content mapping) an exception occurred; it is re-raised with the full messages list attached so the offending input can be identified.
Source
Thrown at litellm/llms/anthropic/chat/transformation.py:1871
if _name_forward_map:
messages = self._rewrite_tool_names_in_messages(messages, _name_forward_map)
if _name_reverse_map and isinstance(litellm_params, dict):
litellm_params[ANTHROPIC_TOOL_NAME_REVERSE_MAP_KEY] = _name_reverse_map
# Separate system prompt from rest of message
anthropic_system_message_list: Final = self.translate_system_message(messages=messages)
# Handling anthropic API Prompt Caching
if len(anthropic_system_message_list) > 0:
optional_params["system"] = anthropic_system_message_list
# Format rest of message according to anthropic guidelines
try:
anthropic_messages = anthropic_messages_pt(
model=model,
messages=messages,
llm_provider=self._resolved_provider,
)
except Exception as e:
raise AnthropicError(
status_code=400,
message=f"{e}\nReceived Messages={messages}",
) # don't use verbose_logger.exception, if exception is raised
## Auto-strip advisor blocks from history if advisor tool is absent.
## Prevents Anthropic 400: advisor_tool_result in history requires advisor tool.
_all_tools: Final = optional_params.get("tools") or []
_has_advisor = any(isinstance(t, dict) and t.get("type") == ANTHROPIC_ADVISOR_TOOL_TYPE for t in _all_tools)
if not _has_advisor:
anthropic_messages = strip_advisor_blocks_from_messages(anthropic_messages)
## Add code_execution tool if container_upload is in messages
_tools: Final = (
cast(
list[AllAnthropicToolsValues | dict] | None,
optional_params.get("tools"),
)
or []View on GitHub (pinned to 77b7c6c40c)
Solutions
- Inspect the messages list shown in the error for malformed entries (bad roles, non-string content blocks).
- Fix the underlying exception '{e}' reported before the message dump.
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at litellm/llms/anthropic/chat/transformation.py:1871 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/5fee267ebec4befe.
Report an issue: GitHub.