{"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/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/prompt_templates/factory.py#L1951-L1987","documentation":"Building an Anthropic block from a file message: the content_block_type extracted from the message did not match any recognized branch (only 'image' and 'container_upload' produce a block in this region), so return_block_param stayed None and the function raises with the message included.","triggerScenarios":"Passing a file content block whose derived content_block_type is something other than 'image' or 'container_upload' - e.g. a document-type file block the converter does not map.","commonSituations":"New file block variants (documents, PDFs) not yet handled by the installed litellm version; provider API drift after Anthropic adds new source types.","solutions":["Use the supported file block shapes: files intended to become images, or container_upload blocks","Send documents through the provider-native document block format on a route that supports it","Upgrade litellm if a newer release added support for your block type"],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"SUPPORTED_FILE_BLOCK_TYPES = {\"image\", \"container_upload\"}\n\ndef file_blocks_supported(messages: list[dict]) -> bool:\n    for m in messages:\n        for block in (m.get(\"content\") or []) if isinstance(m.get(\"content\"), list) else []:\n            if isinstance(block, dict) and block.get(\"type\") == \"file\":\n                f = block.get(\"file\") or {}\n                cbt = f.get(\"type\") or infer_block_type(f)\n                if cbt not in SUPPORTED_FILE_BLOCK_TYPES:\n                    return False\n    return True","typeGuard":"from typing import Any, TypeGuard\n\ndef is_supported_file_block(block: Any) -> TypeGuard[dict]:\n    if not isinstance(block, dict) or block.get(\"type\") != \"file\":\n        return True  # not a file block - nothing to guard\n    f = block.get(\"file\")\n    if not isinstance(f, dict):\n        return False\n    has_source = bool(f.get(\"file_id\") or f.get(\"file_data\"))\n    cbt = f.get(\"type\")\n    return has_source and (cbt is None or cbt in {\"image\", \"container_upload\"})","tryCatchPattern":"try:\n    litellm.completion(model=\"anthropic/claude-...\", messages=messages)\nexcept Exception as e:\n    if \"Unable to parse anthropic file message\" in str(e):\n        # drop or replace the unsupported file block (str(e) names it), then retry\n        messages = drop_unsupported_file_blocks(messages)\n    else:\n        raise","preventionTips":["Restrict file blocks to image-backed files or container_upload in your message builder","Send documents via provider-native document blocks on routes that support them","Upgrade litellm when Anthropic adds new file source types you need"],"tags":["anthropic","file","content-block"],"backgroundTag":"unsupported-content-block","analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}