{"record":{"id":"8a9a0b04deffeed6","repo":"microsoft/semantic-kernel","slug":"unsupported-item-type-in-assistant-message-while-f","errorCode":null,"errorMessage":"Unsupported item type in Assistant message while formatting chat history for Google AI Inference: {type(item)}","messagePattern":"Unsupported item type in Assistant 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":116,"sourceCode":"                    Part(\n                        function_call={\n                            \"name\": item.name,  # type: ignore[arg-type]\n                            \"args\": json.loads(item.arguments) if isinstance(item.arguments, str) else item.arguments,\n                        },\n                        thought_signature=thought_signature,\n                    )\n                )\n            else:\n                parts.append(\n                    Part.from_function_call(\n                        name=item.name,  # type: ignore[arg-type]\n                        args=json.loads(item.arguments) if isinstance(item.arguments, str) else item.arguments,  # type: ignore[arg-type]\n                    )\n                )\n        elif isinstance(item, ImageContent):\n            parts.append(_create_image_part(item))\n        else:\n            raise ServiceInvalidRequestError(\n                \"Unsupported item type in Assistant message while formatting chat history for Google AI\"\n                f\" Inference: {type(item)}\"\n            )\n\n    return parts\n\n\ndef format_tool_message(message: ChatMessageContent) -> list[Part]:\n    \"\"\"Format a tool message to the expected object for the client.\n\n    Args:\n        message: The tool message.\n\n    Returns:\n        The formatted tool message.\n    \"\"\"\n    parts: list[Part] = []\n    for item in message.items:","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/google_ai/services/utils.py#L98-L134","documentation":"Raised by format_assistant_message when a ChatMessageContent item in an assistant-role message is not a TextContent, FunctionCallContent, or ImageContent. The Google AI assistant-message formatter serializes text, function calls (tool invocations), and images only. Any other item type (e.g. FunctionResultContent, BinaryContent) in an assistant message is unsupported.","triggerScenarios":"An assistant-role ChatMessageContent whose items include a type outside {TextContent, FunctionCallContent, ImageContent}, then calling a chat completion method that formats chat history.","commonSituations":"Chat history replay where assistant messages were populated with FunctionResultContent instead of putting results in tool-role messages; cross-connector history migration; custom content subclasses in assistant items.","solutions":["Ensure assistant messages contain only TextContent, FunctionCallContent, or ImageContent.","Move FunctionResultContent items into tool-role messages (add_message(role=AuthorRole.TOOL, ...)) rather than assistant messages.","Pre-validate assistant-message items before sending to the Google AI service."],"exampleFix":"# before\nhistory.add_message(\n    role=AuthorRole.ASSISTANT,\n    items=[TextContent(text='calling tool'), FunctionResultContent(id='1', name='search', result='{...}')],\n)\n\n# after\nhistory.add_message(role=AuthorRole.ASSISTANT, items=[TextContent(text='calling tool')])\nhistory.add_message(role=AuthorRole.TOOL, items=[FunctionResultContent(id='1', name='search', result='{...}')])","handlingStrategy":"type-guard","validationCode":"from semantic_kernel.contents.text_content import TextContent\nfrom semantic_kernel.contents.image_content import ImageContent\nfrom semantic_kernel.contents.function_call_content import FunctionCallContent\n\nALLOWED = (TextContent, ImageContent, FunctionCallContent)\ndef validate_assistant_items(message):\n    for item in message.items:\n        if not isinstance(item, ALLOWED):\n            raise TypeError(f'Unsupported assistant item type: {type(item).__name__}')","typeGuard":"from semantic_kernel.contents.text_content import TextContent\nfrom semantic_kernel.contents.image_content import ImageContent\nfrom semantic_kernel.contents.function_call_content import FunctionCallContent\n\ndef is_valid_assistant_item(item) -> bool:\n    return isinstance(item, (TextContent, ImageContent, FunctionCallContent))","tryCatchPattern":null,"preventionTips":["Put FunctionResultContent in tool-role messages, not assistant messages.","Validate assistant-message items before sending to Google AI.","When migrating history from another connector, normalize item types per role."],"tags":["google-ai","chat-history","content-type","assistant-message","function-calling","serialization"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}