{"record":{"id":"5fee267ebec4befe","repo":"BerriAI/litellm","slug":"e-received-messages-messages","errorCode":null,"errorMessage":"{e}\nReceived Messages={messages}","messagePattern":"(.+?)\nReceived Messages=(.+?)","errorType":"validation","errorClass":"AnthropicError","httpStatus":400,"severity":"error","filePath":"litellm/llms/anthropic/chat/transformation.py","lineNumber":1871,"sourceCode":"        if _name_forward_map:\n            messages = self._rewrite_tool_names_in_messages(messages, _name_forward_map)\n        if _name_reverse_map and isinstance(litellm_params, dict):\n            litellm_params[ANTHROPIC_TOOL_NAME_REVERSE_MAP_KEY] = _name_reverse_map\n\n        # Separate system prompt from rest of message\n        anthropic_system_message_list: Final = self.translate_system_message(messages=messages)\n        # Handling anthropic API Prompt Caching\n        if len(anthropic_system_message_list) > 0:\n            optional_params[\"system\"] = anthropic_system_message_list\n        # Format rest of message according to anthropic guidelines\n        try:\n            anthropic_messages = anthropic_messages_pt(\n                model=model,\n                messages=messages,\n                llm_provider=self._resolved_provider,\n            )\n        except Exception as e:\n            raise AnthropicError(\n                status_code=400,\n                message=f\"{e}\\nReceived Messages={messages}\",\n            )  # don't use verbose_logger.exception, if exception is raised\n\n        ## Auto-strip advisor blocks from history if advisor tool is absent.\n        ## Prevents Anthropic 400: advisor_tool_result in history requires advisor tool.\n        _all_tools: Final = optional_params.get(\"tools\") or []\n        _has_advisor = any(isinstance(t, dict) and t.get(\"type\") == ANTHROPIC_ADVISOR_TOOL_TYPE for t in _all_tools)\n        if not _has_advisor:\n            anthropic_messages = strip_advisor_blocks_from_messages(anthropic_messages)\n\n        ## Add code_execution tool if container_upload is in messages\n        _tools: Final = (\n            cast(\n                list[AllAnthropicToolsValues | dict] | None,\n                optional_params.get(\"tools\"),\n            )\n            or []","sourceCodeStart":1853,"sourceCodeEnd":1889,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/llms/anthropic/chat/transformation.py#L1853-L1889","documentation":"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.","triggerScenarios":"Thrown at litellm/llms/anthropic/chat/transformation.py:1871 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}