{"record":{"id":"cd2048aa298ae352","repo":"microsoft/semantic-kernel","slug":"unsupported-item-type-in-user-message-while-format-cd2048","errorCode":null,"errorMessage":"Unsupported item type in User message while formatting chat history for Vertex AI Inference: {type(item)}","messagePattern":"Unsupported item type in User message while formatting chat history for Vertex AI Inference: (.+?)","errorType":"exception","errorClass":"ServiceInvalidRequestError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/google/vertex_ai/services/utils.py","lineNumber":70,"sourceCode":"\n\ndef format_user_message(message: ChatMessageContent) -> list[Part]:\n    \"\"\"Format a user message to the expected object for the client.\n\n    Args:\n        message: The user message.\n\n    Returns:\n        The formatted user message as a list of parts.\n    \"\"\"\n    parts: list[Part] = []\n    for item in message.items:\n        if isinstance(item, TextContent):\n            parts.append(Part.from_text(item.text))\n        elif isinstance(item, ImageContent):\n            parts.append(_create_image_part(item))\n        else:\n            raise ServiceInvalidRequestError(\n                \"Unsupported item type in User message while formatting chat history for Vertex AI\"\n                f\" Inference: {type(item)}\"\n            )\n\n    return parts\n\n\ndef format_assistant_message(message: ChatMessageContent) -> list[Part]:\n    \"\"\"Format an assistant message to the expected object for the client.\n\n    Args:\n        message: The assistant message.\n\n    Returns:\n        The formatted assistant message as a list of parts.\n    \"\"\"\n    parts: list[Part] = []\n    for item in message.items:","sourceCodeStart":52,"sourceCodeEnd":88,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/vertex_ai/services/utils.py#L52-L88","documentation":"Raised by format_user_message() in the Vertex AI connector when it iterates a user message's items and encounters a content item that is neither TextContent nor ImageContent. The Vertex AI Inference API only accepts text and inline-image parts in a user role, so any other content type is rejected before the request is sent. The message embeds the offending item's Python type so you can see exactly what was unsupported.","triggerScenarios":"Calling VertexAIChatCompletion with a ChatHistory whose user message contains an item other than TextContent/ImageContent (e.g. FunctionCallContent, FunctionResultContent, BinaryContent, AudioContent, or a custom ChatMessageContent item). Happens when reusing a chat history built for another connector, or when appending a tool result into a user-role message.","commonSituations":"Porting a chat history authored for OpenAI/Azure (which tolerates mixed content) over to Vertex AI. Mixing tool-call round-trips into user messages instead of assistant/tool roles. Constructing ChatMessageContent with a generic item list rather than typed TextContent.","solutions":["Inspect the {type(item)} in the error and ensure user-role messages only contain TextContent (and optionally ImageContent) items.","Move FunctionCallContent into an assistant-role message and FunctionResultContent into a tool-role message before calling the Vertex AI service.","Strip or convert unsupported items (e.g. serialize BinaryContent to text) before adding the message to ChatHistory.","If you need a content type Vertex AI doesn't support, build the message via a role the Vertex AI formatter handles (tool/assistant) or pre-flatten the item to TextContent."],"exampleFix":"// before\nhistory.add_user_message(items=[FunctionResultContent(id=..., result=...), TextContent(text='hi')])\n# after\nhistory.add_message(role=AuthorRole.TOOL, items=[FunctionResultContent(id=..., result=...)])\nhistory.add_user_message(text='hi')","handlingStrategy":"validation","validationCode":"from semantic_kernel.contents import TextContent, ImageContent\nSUPPORTED = (TextContent, ImageContent)\nbad = [type(i) for i in user_msg.items if not isinstance(i, SUPPORTED)]\nassert not bad, f'Unsupported user-role items: {bad}'","typeGuard":"def is_valid_vertex_user_message(msg) -> bool:\n    return all(isinstance(i, (TextContent, ImageContent)) for i in msg.items)","tryCatchPattern":null,"preventionTips":["Standardize ChatHistory construction so user-role messages only carry TextContent/ImageContent.","Route FunctionResultContent to tool role and FunctionCallContent to assistant role.","Add a unit test asserting per-role item types before calling the Vertex AI service."],"tags":["vertex-ai","chat-history","content-types","validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}