BerriAI/litellm · error · Exception
Unable to parse anthropic file message
Error message
Unable to parse anthropic file message: {message} What it means
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.
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
Defensive patterns
Strategy: type-guard
Validate before calling
SUPPORTED_FILE_BLOCK_TYPES = {"image", "container_upload"}
def file_blocks_supported(messages: list[dict]) -> bool:
for m in messages:
for block in (m.get("content") or []) if isinstance(m.get("content"), list) else []:
if isinstance(block, dict) and block.get("type") == "file":
f = block.get("file") or {}
cbt = f.get("type") or infer_block_type(f)
if cbt not in SUPPORTED_FILE_BLOCK_TYPES:
return False
return True Type guard
from typing import Any, TypeGuard
def is_supported_file_block(block: Any) -> TypeGuard[dict]:
if not isinstance(block, dict) or block.get("type") != "file":
return True # not a file block - nothing to guard
f = block.get("file")
if not isinstance(f, dict):
return False
has_source = bool(f.get("file_id") or f.get("file_data"))
cbt = f.get("type")
return has_source and (cbt is None or cbt in {"image", "container_upload"}) Try / catch
try:
litellm.completion(model="anthropic/claude-...", messages=messages)
except Exception as e:
if "Unable to parse anthropic file message" in str(e):
# drop or replace the unsupported file block (str(e) names it), then retry
messages = drop_unsupported_file_blocks(messages)
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: New file block variants (documents, PDFs) not yet handled by the installed litellm version; provider API drift after Anthropic adds new source 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…
- Azure Anthropic requests require an api_base. Set…
- {error_text}
- file_id and file_data are both None
- Image url not in expected format. Example Expected input -…
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/aa89f4e284129f86.
Report an issue: GitHub.
Appendix: 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 77b7c6c40c)