unslothai/unsloth · info · ValueError
known block type handled by its typed model
Error message
known block type handled by its typed model
What it means
Internal sentinel raised by AnthropicUnknownBlock's type validator when a block whose type is in _KNOWN_ANTHROPIC_BLOCK_TYPES reaches the fallback model. The Union is ordered so known types (text/image/tool_use/tool_result) parse as their typed models first; only genuinely unknown types should land here. Seeing this message means the discriminators did not route a known block to its typed model — effectively an internal invariant, not a client error.
Source
Thrown at studio/backend/models/inference.py:2456
# Block types the converter translates explicitly. Anything else (thinking /
# redacted_thinking, a provider block a resumed session replays, or a future type)
# is accepted as an unknown block and dropped by the converter, rather than 400-ing
# the whole request on strict validation.
_KNOWN_ANTHROPIC_BLOCK_TYPES = frozenset({"text", "image", "tool_use", "tool_result"})
class AnthropicUnknownBlock(BaseModel):
type: str
model_config = {"extra": "allow"}
@field_validator("type")
@classmethod
def _only_unknown_types(cls, v):
# Known types parse as their typed models above (so a malformed known block
# still fails cleanly); this fallback only catches the rest.
if v in _KNOWN_ANTHROPIC_BLOCK_TYPES:
raise ValueError("known block type handled by its typed model")
return v
AnthropicContentBlock = Union[
AnthropicTextBlock,
AnthropicImageBlock,
AnthropicToolUseBlock,
AnthropicToolResultBlock,
AnthropicUnknownBlock,
]
def _anthropic_content_to_system_text(content: Any) -> str:
"""Convert misplaced system message content into Anthropic system text."""
if content is None: # null content must not become the literal "None"
return ""
if isinstance(content, str):
return contentView on GitHub (pinned to 203007d190)
Solutions
- Inspect the failing block JSON and fix the malformed known-type block (missing/incorrect fields).
- If you maintain the server, check that the typed block models still accept legitimate payloads after an upgrade.
- Do not attempt to send known-type blocks through the 'unknown block' escape hatch — the validator forbids it by design.
Example fix
// before
{"type": "text", "text": null} // null text fails AnthropicTextBlock, falls through
// after
{"type": "text", "text": "hello"} Defensive patterns
Strategy: try-catch
Validate before calling
KNOWN = {'text', 'image', 'tool_use', 'tool_result'}
def block_parses_as_known(block: dict) -> bool:
# best-effort client mirror; full checking belongs to the server models
return block.get('type') in KNOWN Type guard
def is_unknown_block(block: dict) -> bool:
return isinstance(block.get('type'), str) and block['type'] not in {
'text', 'image', 'tool_use', 'tool_result'
} Try / catch
try:
req = AnthropicMessagesRequest.model_validate_json(body)
except ValidationError:
# inspect which block failed; fix the malformed known-type block
log_and_return_400()
Prevention
- Treat this message as an internal invariant: the block payload is malformed for its declared known type
- Keep typed block models in lockstep with upstream schema changes
- Fuzz-test block endpoints with mutated payloads to catch drift early
When it happens
Trigger: A content block with type 'text'/'image'/etc. that is malformed enough to fail its typed model's parsing (so Pydantic tries the fallback) — for example a text block missing required fields. Under Pydantic smart union the fallback then also rejects it, collapsing to a clean validation error rather than a silent passthrough.
Common situations: Gateway/proxy tests that construct half-valid Anthropic blocks; upstream schema drift adding a required field to a known block model so previously valid blocks no longer match the typed model; fuzzing the messages endpoint with mutated block payloads.
Related errors
- unsupported content block type {btype!r} in a user message
- Provide either content_base64 or file_ids, not both
- Provide either content_base64 or file_ids
- file_ids must not be empty
- block_id is required when using file_ids
AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15).
Data as JSON: /api/errors/3259d0a0edd33824.
Report an issue: GitHub.