{"record":{"id":"6af9736d737c0bcb","repo":"microsoft/autogen","slug":"unknown-content-type-part","errorCode":null,"errorMessage":"Unknown content type: {part}","messagePattern":"Unknown content type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py","lineNumber":225,"sourceCode":"    else:\n        blocks: List[Union[TextBlockParam, ImageBlockParam]] = []\n\n        for part in message.content:\n            if isinstance(part, str):\n                blocks.append(TextBlockParam(type=\"text\", text=__empty_content_to_whitespace(part)))\n            elif isinstance(part, Image):\n                blocks.append(\n                    ImageBlockParam(\n                        type=\"image\",\n                        source=Base64ImageSourceParam(\n                            type=\"base64\",\n                            media_type=get_mime_type_from_image(part),\n                            data=part.to_base64(),\n                        ),\n                    )\n                )\n            else:\n                raise ValueError(f\"Unknown content type: {part}\")\n\n        return {\n            \"role\": \"user\",\n            \"content\": blocks,\n        }\n\n\ndef system_message_to_anthropic(message: SystemMessage) -> str:\n    return __empty_content_to_whitespace(message.content)\n\n\ndef assistant_message_to_anthropic(message: AssistantMessage) -> MessageParam:\n    assert_valid_name(message.source)\n\n    if isinstance(message.content, list):\n        # Tool calls\n        tool_use_blocks: List[ToolUseBlock] = []\n","sourceCodeStart":207,"sourceCodeEnd":243,"githubUrl":"https://github.com/microsoft/autogen/blob/027ecf0a379bcc1d09956d46d12d44a3ad9cee14/python/packages/autogen-ext/src/autogen_ext/models/anthropic/_anthropic_client.py#L207-L243","documentation":"When converting a UserMessage with multi-part content into Anthropic blocks, the client handles str parts and Image parts explicitly. Any other object in the content list (a dict, a custom class, bytes, None) hits the else branch and raises ValueError('Unknown content type: {part}'). This keeps malformed message content from reaching the Anthropic API.","triggerScenarios":"UserMessage(content=[{'type': 'text', 'text': 'hi'}], ...) using Anthropic-native dicts instead of autogen types; a list mixing in None or FunctionCall objects; a custom content class not derived from str/Image.","commonSituations":"Translating raw Anthropic/OpenAI message payloads into autogen messages and forgetting to unwrap dicts to plain strings; spreading optional parts into the list (None placeholders); version drift where a new content type exists in core but not in this client.","solutions":["Build multi-part content from plain str and autogen_core.Image instances only.","Unwrap API-style dicts to their text/image equivalents before constructing UserMessage.","Filter the list: [p for p in parts if isinstance(p, (str, Image))] to drop None/unsupported entries."],"exampleFix":"# before\nmsg = UserMessage(content=[{'type': 'text', 'text': 'analyze this'}, img], source='user')  # ValueError\n\n# after\nmsg = UserMessage(content=['analyze this', img], source='user')","handlingStrategy":"type-guard","validationCode":"from autogen_core import Image\n\ndef clean_parts(parts):\n    out = []\n    for p in parts:\n        if isinstance(p, str):\n            out.append(p)\n        elif isinstance(p, Image):\n            out.append(p)\n        elif isinstance(p, dict) and p.get('type') == 'text':\n            out.append(p['text'])\n        # else dropped\n    return out","typeGuard":"def is_supported_part(p) -> bool:\n    return isinstance(p, (str, Image))","tryCatchPattern":"try:\n    res = await client.create([UserMessage(content=parts, source='user')])\nexcept ValueError as e:\n    if 'Unknown content type' in str(e):\n        parts = [p for p in parts if isinstance(p, (str, Image))]\n        res = await client.create([UserMessage(content=parts, source='user')])\n    else:\n        raise","preventionTips":["Construct multi-part content only from str and Image","Unwrap API-format dicts before building UserMessage","Sanitize history loaded from persistence before replay"],"tags":["anthropic","message-content","llm-client","type-error"],"backgroundTag":null,"analyzedSha":"027ecf0a379bcc1d09956d46d12d44a3ad9cee14","analyzedAt":"2026-08-15T03:38:00.719Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}