{"record":{"id":"02d396744625fa1f","repo":"deepset-ai/haystack","slug":"unsupported-content-type-type-part","errorCode":null,"errorMessage":"Unsupported content type: {type(part)}","messagePattern":"Unsupported content type: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/components/generators/chat/openai_responses.py","lineNumber":986,"sourceCode":"\n    def convert_part(part: Any) -> dict[str, str | None]:\n        if isinstance(part, TextContent):\n            return {\"type\": \"input_text\", \"text\": part.text}\n        if isinstance(part, ImageContent):\n            return {\n                \"type\": \"input_image\",\n                # If no MIME type is provided, default to JPEG. OpenAI API appears to tolerate MIME type mismatches.\n                \"image_url\": f\"data:{part.mime_type or 'image/jpeg'};base64,{part.base64_image}\",\n            }\n        if isinstance(part, FileContent):\n            return {\n                \"type\": \"input_file\",\n                # Filename is optional but if not provided, OpenAI expects a file_id of a previous file upload.\n                # We use a dummy filename to avoid this issue.\n                \"filename\": part.filename or \"filename\",\n                \"file_data\": f\"data:{part.mime_type or 'application/pdf'};base64,{part.base64_data}\",\n            }\n        raise ValueError(f\"Unsupported content type: {type(part)}\")\n\n    text_contents = message.texts\n    tool_calls = message.tool_calls\n    tool_call_results = message.tool_call_results\n    images = message.images\n    reasonings = message.reasonings\n    files = message.files\n\n    if not any([text_contents, tool_calls, tool_call_results, images, reasonings, files]):\n        raise ValueError(\n            \"\"\"A `ChatMessage` must contain at least one `TextContent`, `ToolCall`, `ToolCallResult`,\n              `ImageContent`, `FileContent`, or `ReasoningContent`.\"\"\"\n        )\n    if len(tool_call_results) > 0 and len(message._content) > 1:\n        raise ValueError(\n            \"For OpenAI compatibility, a `ChatMessage` with a `ToolCallResult` cannot contain any other content.\"\n        )\n","sourceCodeStart":968,"sourceCodeEnd":1004,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/generators/chat/openai_responses.py#L968-L1004","documentation":"When converting a ChatMessage to the OpenAI Responses API format, each content part must be a known type (text, image, file). `convert_part` raises ValueError for any unrecognized content part class, meaning the message contains a content type haystack cannot map to the Responses API.","triggerScenarios":"A ChatMessage whose _content contains a part type not handled by convert_part — e.g. a custom/ReasoningContent part or an unexpected content class in a message passed to OpenAIResponsesChatGenerator.","commonSituations":"Messages built programmatically with custom content parts; passing messages produced by other backends (e.g. reasoning traces) directly to the Responses API converter.","solutions":["Remove unsupported content parts from the message before calling the generator","Convert unsupported parts to TextContent/FileContent/ImageContent equivalents","Inspect `message._content` types and filter to supported types"],"exampleFix":"// before\nmsg = ChatMessage(_role=ChatRole.USER, _content=[unsupported_part])\n// after\nmsg = ChatMessage.from_user(\"text equivalent of the content\")","handlingStrategy":"validation","validationCode":"from haystack.dataclasses import TextContent, ImageContent, FileContent\nallowed = (TextContent, ImageContent, FileContent)\nfor m in messages:\n    assert all(isinstance(p, allowed) for p in m._content), [type(p) for p in m._content]","typeGuard":"def is_supported_part(p) -> bool:\n    from haystack.dataclasses import TextContent, ImageContent, FileContent\n    return isinstance(p, (TextContent, ImageContent, FileContent))","tryCatchPattern":"try:\n    gen.run(messages=messages)\nexcept ValueError as e:\n    if \"Unsupported content type\" in str(e):\n        messages = [filter_supported(m) for m in messages]","preventionTips":["Build messages only with haystack content dataclasses","Don't pass foreign/custom content parts","Filter message contents before the Responses API"],"tags":["python","haystack","openai","content-parts","responses-api"],"backgroundTag":"unsupported-content-type","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}