{"record":{"id":"e318d72e79dc2f8e","repo":"microsoft/semantic-kernel","slug":"unsupported-item-type-in-assistant-message-while-f-e318d7","errorCode":null,"errorMessage":"Unsupported item type in Assistant message while formatting chat history for Vertex AI Inference: {type(item)}","messagePattern":"Unsupported item type in Assistant 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":106,"sourceCode":"    for item in message.items:\n        if isinstance(item, TextContent):\n            if item.text:\n                parts.append(Part.from_text(item.text))\n        elif isinstance(item, FunctionCallContent):\n            part_dict: dict[str, Any] = {\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            }\n            thought_signature = item.metadata.get(\"thought_signature\") if item.metadata else None\n            if thought_signature:\n                part_dict[\"thought_signature\"] = thought_signature\n            parts.append(Part.from_dict(part_dict))\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 Vertex 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":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/google/vertex_ai/services/utils.py#L88-L124","documentation":"Raised by format_assistant_message() in the Vertex AI connector when an assistant message contains an item that is not TextContent, FunctionCallContent, or ImageContent. The Vertex AI API models assistant turns as text, function calls, and images, so other item kinds are rejected during chat-history formatting. The offending item's type is reported in the message.","triggerScenarios":"Sending a ChatHistory whose assistant message includes a FunctionResultContent (tool result placed in the wrong role), a StreamingChatMessageContent item, or any non-text/non-function-call item. Also triggered by replaying a recorded history from a different provider.","commonSituations":"Putting tool results under the assistant role instead of the tool role. Reusing serialized histories from OpenAI pipelines. Adding custom content classes to assistant messages that Vertex AI's formatter does not recognize.","solutions":["Keep assistant messages limited to TextContent, FunctionCallContent, and ImageContent items only.","Relocate FunctionResultContent into a tool-role message (format_tool_message handles it) before the Vertex AI call.","If you must carry extra metadata, store it in ChatMessageContent.metadata rather than as an unhandled item.","Log message.items per role during testing to catch stray item types early."],"exampleFix":"// before\nhistory.add_message(role=AuthorRole.ASSISTANT, items=[TextContent(text='ok'), FunctionResultContent(...)])\n# after\nhistory.add_message(role=AuthorRole.ASSISTANT, items=[TextContent(text='ok'), FunctionCallContent(...)])\nhistory.add_message(role=AuthorRole.TOOL, items=[FunctionResultContent(...)])","handlingStrategy":"validation","validationCode":"from semantic_kernel.contents import TextContent, ImageContent, FunctionCallContent\nSUPPORTED = (TextContent, FunctionCallContent, ImageContent)\nbad = [type(i) for i in assistant_msg.items if not isinstance(i, SUPPORTED)]\nassert not bad, f'Unsupported assistant-role items: {bad}'","typeGuard":"def is_valid_vertex_assistant_message(msg) -> bool:\n    ok = (TextContent, FunctionCallContent, ImageContent)\n    return all(isinstance(i, ok) for i in msg.items)","tryCatchPattern":null,"preventionTips":["Keep assistant messages to text, function-call, and image items only.","Move tool results into tool-role messages.","Store extra info in ChatMessageContent.metadata rather than custom items."],"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"}