{"record":{"id":"24a44e1d5659bbcb","repo":"microsoft/semantic-kernel","slug":"unsupported-item-type-in-user-message-while-format","errorCode":null,"errorMessage":"Unsupported item type in User message while formatting chat history for Google AI Inference: {type(item)}","messagePattern":"Unsupported item type in User message while formatting chat history for Google AI Inference: (.+?)","errorType":"exception","errorClass":"ServiceInvalidRequestError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/google/google_ai/services/utils.py","lineNumber":72,"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(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 Google 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":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/google_ai/services/utils.py#L54-L90","documentation":"Raised by format_user_message when a ChatMessageContent item in a user-role message is neither a TextContent nor an ImageContent. The Google AI Gemini API user-message formatter only handles text and inline images; any other item type (e.g. FunctionResultContent, BinaryContent, custom content subclasses) is unsupported and the request cannot be serialized for the API.","triggerScenarios":"Adding a user-role ChatMessageContent with an items list containing a type other than TextContent/ImageContent (e.g. a FunctionResultContent, a BinaryContent, or a custom content type) and then calling a chat completion method.","commonSituations":"Manually constructing chat history with unsupported item types; piping output from another connector that produces item types Google AI doesn't understand; adding binary/audio content as a user item.","solutions":["Ensure every item in a user message is a TextContent or ImageContent before sending to Google AI.","Convert or serialize unsupported items to text (e.g. str(result)) before adding them to user-message items.","Filter chat history to strip or transform unsupported item types prior to the API call."],"exampleFix":"# before\nhistory.add_user_message(items=[\n    TextContent(text='describe this'),\n    BinaryContent(data=b'...', mime_type='audio/wav'),  # unsupported\n])\n\n# after\nhistory.add_user_message(items=[\n    TextContent(text='describe this'),\n    ImageContent(data=image_bytes, mime_type='image/png', data_uri='inline'),\n])","handlingStrategy":"type-guard","validationCode":"from semantic_kernel.contents.text_content import TextContent\nfrom semantic_kernel.contents.image_content import ImageContent\n\ndef validate_user_items(message):\n    for item in message.items:\n        if not isinstance(item, (TextContent, ImageContent)):\n            raise TypeError(f'Unsupported user item type: {type(item).__name__}')","typeGuard":"from semantic_kernel.contents.text_content import TextContent\nfrom semantic_kernel.contents.image_content import ImageContent\n\ndef is_valid_user_item(item) -> bool:\n    return isinstance(item, (TextContent, ImageContent))","tryCatchPattern":null,"preventionTips":["Only add TextContent and ImageContent items to user messages for Google AI.","Build a helper that constructs user messages from plain strings to avoid accidental unsupported types.","Sanitize cross-connector chat history before passing to the Google AI service."],"tags":["google-ai","chat-history","content-type","user-message","serialization"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}