BerriAI/litellm · error · ValueError
Unknown Anthropic content type
Error message
Unknown Anthropic content type: '{content_type}' What it means
Anthropic content validation guard: the content block's 'type' is not one of the recognized Anthropic types (tool_use, tool_result), so no TypedDict applies. Fires on unsupported content types passed through Anthropic message counting.
Solutions
- Use a supported Anthropic content type (text, image, tool_use, tool_result, etc.).
- Fix or remove the unknown content block type.
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/litellm_core_utils/token_counter.py:627 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18).
Data as JSON: /api/errors/fb39f08f339a0cce.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/litellm_core_utils/token_counter.py:627
def _validate_anthropic_content(content: Mapping[str, Any]) -> type:
"""
Validate and determine which Anthropic TypedDict applies.
Returns the corresponding TypedDict class if recognized, otherwise raises.
"""
content_type: Final = content.get("type")
if not content_type:
raise ValueError("Anthropic content missing required field: 'type'")
mapping: Final = {
"tool_use": AnthropicMessagesToolUseParam,
"tool_result": AnthropicMessagesToolResultParam,
}
expected_cls: Final = mapping.get(content_type)
if expected_cls is None:
raise ValueError(f"Unknown Anthropic content type: '{content_type}'")
missing: Final = [k for k in getattr(expected_cls, "__required_keys__", set()) if k not in content]
if missing:
raise ValueError(f"Missing required fields in {content_type} block: {', '.join(missing)}")
return expected_cls
def _count_anthropic_content(
content: Mapping[str, Any],
count_function: TokenCounterFunction,
use_default_image_token_count: bool,
default_token_count: int | None,
) -> int:
"""
Count tokens in Anthropic-specific content blocks (tool_use, tool_result, etc.).
Uses TypedDict definitions from litellm.types.llms.anthropic to determineView on GitHub (pinned to 77b7c6c40c)