BerriAI/litellm · error · Exception
Unable to parse anthropic file message: {message}
Error message
Unable to parse anthropic file message: {message} What it means
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.
Source
Thrown at litellm/litellm_core_utils/prompt_templates/factory.py:1969
type="document",
source=AnthropicContentParamSourceUrl(
type="url",
url=file_id,
),
)
elif content_block_type == "image":
return_block_param = AnthropicMessagesImageParam(
type="image",
source=AnthropicContentParamSourceFileId(
type="file",
file_id=file_id,
),
)
elif content_block_type == "container_upload":
return_block_param = AnthropicMessagesContainerUploadParam(type="container_upload", file_id=file_id)
if return_block_param is None:
raise Exception(f"Unable to parse anthropic file message: {message}")
return return_block_param
raise Exception(f"Either file_data or file_id must be present in the file message: {message}")
_EMPTY_TEXT_PLACEHOLDER: Final = "[System: Empty message content sanitised to satisfy protocol]"
def _sanitize_empty_text_content(
message: AllMessageValues,
) -> AllMessageValues:
"""
Case C: Sanitize empty text content
- Replace empty or whitespace-only text content with a placeholder message.
- Handles both string content and list-of-blocks content (rewriting only
the empty text blocks in place; non-text blocks like images are left
untouched).
Returns:View on GitHub (pinned to 6c2dcb801b)
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
Example fix
# before
{"type": "file", "file": {"file_id": "file_abc", "content_block_type": "audio"}}
# after
{"type": "file", "file": {"file_id": "file_abc", "content_block_type": "document"}} Defensive patterns
Strategy: validation
Validate before calling
SUPPORTED_FILE_BLOCK_TYPES = {"image", "document", "container_upload"}
def validate_file_blocks(messages) -> None:
for m in messages:
for block in m.get("content", []) if isinstance(m.get("content"), list) else []:
if isinstance(block, dict) and block.get("type") == "file":
cbt = block.get("file", {}).get("content_block_type")
if cbt not in SUPPORTED_FILE_BLOCK_TYPES:
raise ValueError(f"unsupported file content_block_type: {cbt}") Type guard
from typing import Any
_OK = {"image", "document", "container_upload"}
def is_supported_file_block(block: Any) -> bool:
return (
isinstance(block, dict)
and block.get("type") == "file"
and isinstance(block.get("file"), dict)
and block["file"].get("content_block_type") in _OK
) Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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).
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Either file_data or file_id must be present in the file mess
- file_id is required in file_content_request
- File data is required
- WebSearchInterception: missing follow-up messages
- file_id and file_data are both None
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/aa89f4e284129f86.
Report an issue: GitHub.