{"record":{"id":"aa89f4e284129f86","repo":"BerriAI/litellm","slug":"unable-to-parse-anthropic-file-message-message","errorCode":null,"errorMessage":"Unable to parse anthropic file message: {message}","messagePattern":"Unable to parse anthropic file message: (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/prompt_templates/factory.py","lineNumber":1969,"sourceCode":"                type=\"document\",\n                source=AnthropicContentParamSourceUrl(\n                    type=\"url\",\n                    url=file_id,\n                ),\n            )\n        elif content_block_type == \"image\":\n            return_block_param = AnthropicMessagesImageParam(\n                type=\"image\",\n                source=AnthropicContentParamSourceFileId(\n                    type=\"file\",\n                    file_id=file_id,\n                ),\n            )\n        elif content_block_type == \"container_upload\":\n            return_block_param = AnthropicMessagesContainerUploadParam(type=\"container_upload\", file_id=file_id)\n\n        if return_block_param is None:\n            raise Exception(f\"Unable to parse anthropic file message: {message}\")\n        return return_block_param\n    raise Exception(f\"Either file_data or file_id must be present in the file message: {message}\")\n\n\n_EMPTY_TEXT_PLACEHOLDER: Final = \"[System: Empty message content sanitised to satisfy protocol]\"\n\n\ndef _sanitize_empty_text_content(\n    message: AllMessageValues,\n) -> AllMessageValues:\n    \"\"\"\n    Case C: Sanitize empty text content\n    - Replace empty or whitespace-only text content with a placeholder message.\n    - Handles both string content and list-of-blocks content (rewriting only\n      the empty text blocks in place; non-text blocks like images are left\n      untouched).\n\n    Returns:","sourceCodeStart":1951,"sourceCodeEnd":1987,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/prompt_templates/factory.py#L1951-L1987","documentation":"While converting a file content block for Anthropic: file_data/file_id was present, but the block's type was not one of the handled kinds (e.g. 'image', 'document', 'container_upload' branches), so return_block_param stayed None. The error includes the full message so you can see the unsupported type value.","triggerScenarios":"Sending {\"type\": \"file\", \"file\": {\"file_id\": ..., \"content_block_type\": \"audio\"}} (or any unrecognized content_block_type) to a Claude model; content_block_type values introduced by newer API versions that this LiteLLM version does not map.","commonSituations":"Forwarding raw Anthropic API file blocks that use newer content types; mismatches between the content_block_type string stored by your app and what this LiteLLM release supports (upgrade fixes new types).","solutions":["Use a supported content_block_type: 'image', 'document', or 'container_upload' (per this source)","Upgrade LiteLLM to a version that supports the file block type you are sending","Convert the file to a supported representation, e.g. inline PDF bytes as a base64 document source instead"],"exampleFix":"# before\n{\"type\": \"file\", \"file\": {\"file_id\": \"file_abc\", \"content_block_type\": \"audio\"}}\n\n# after\n{\"type\": \"file\", \"file\": {\"file_id\": \"file_abc\", \"content_block_type\": \"document\"}}","handlingStrategy":"validation","validationCode":"SUPPORTED_FILE_BLOCK_TYPES = {\"image\", \"document\", \"container_upload\"}\n\ndef validate_file_blocks(messages) -> None:\n    for m in messages:\n        for block in m.get(\"content\", []) if isinstance(m.get(\"content\"), list) else []:\n            if isinstance(block, dict) and block.get(\"type\") == \"file\":\n                cbt = block.get(\"file\", {}).get(\"content_block_type\")\n                if cbt not in SUPPORTED_FILE_BLOCK_TYPES:\n                    raise ValueError(f\"unsupported file content_block_type: {cbt}\")","typeGuard":"from typing import Any\n\n_OK = {\"image\", \"document\", \"container_upload\"}\n\ndef is_supported_file_block(block: Any) -> bool:\n    return (\n        isinstance(block, dict)\n        and block.get(\"type\") == \"file\"\n        and isinstance(block.get(\"file\"), dict)\n        and block[\"file\"].get(\"content_block_type\") in _OK\n    )","tryCatchPattern":null,"preventionTips":["Restrict file content_block_type to image/document/container_upload","Keep LiteLLM updated when Anthropic adds new file block types","Convert novel file types to base64 document sources"],"tags":["anthropic","files","content-block","validation"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}