microsoft/semantic-kernel · error · ServiceInvalidRequestError
Unsupported item type in Assistant message while formatting
Error message
Unsupported item type in Assistant message while formatting chat history for Vertex AI Inference: {type(item)} What it means
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.
Source
Thrown at python/semantic_kernel/connectors/ai/google/vertex_ai/services/utils.py:106
for item in message.items:
if isinstance(item, TextContent):
if item.text:
parts.append(Part.from_text(item.text))
elif isinstance(item, FunctionCallContent):
part_dict: dict[str, Any] = {
"function_call": {
"name": item.name, # type: ignore[arg-type]
"args": json.loads(item.arguments) if isinstance(item.arguments, str) else item.arguments,
}
}
thought_signature = item.metadata.get("thought_signature") if item.metadata else None
if thought_signature:
part_dict["thought_signature"] = thought_signature
parts.append(Part.from_dict(part_dict))
elif isinstance(item, ImageContent):
parts.append(_create_image_part(item))
else:
raise ServiceInvalidRequestError(
"Unsupported item type in Assistant message while formatting chat history for Vertex AI"
f" Inference: {type(item)}"
)
return parts
def format_tool_message(message: ChatMessageContent) -> list[Part]:
"""Format a tool message to the expected object for the client.
Args:
message: The tool message.
Returns:
The formatted tool message.
"""
parts: list[Part] = []
for item in message.items:View on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before history.add_message(role=AuthorRole.ASSISTANT, items=[TextContent(text='ok'), FunctionResultContent(...)]) # after history.add_message(role=AuthorRole.ASSISTANT, items=[TextContent(text='ok'), FunctionCallContent(...)]) history.add_message(role=AuthorRole.TOOL, items=[FunctionResultContent(...)])
Defensive patterns
Strategy: validation
Validate before calling
from semantic_kernel.contents import TextContent, ImageContent, FunctionCallContent
SUPPORTED = (TextContent, FunctionCallContent, ImageContent)
bad = [type(i) for i in assistant_msg.items if not isinstance(i, SUPPORTED)]
assert not bad, f'Unsupported assistant-role items: {bad}' Type guard
def is_valid_vertex_assistant_message(msg) -> bool:
ok = (TextContent, FunctionCallContent, ImageContent)
return all(isinstance(i, ok) for i in msg.items) Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unsupported item type in User message while formatting chat
- Chat history can't contain only system messages.
- Chat history must contain at least one message
- The first message in chat history must have either the syste
- System messages cannot be added to the chat history.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/e318d72e79dc2f8e.
Report an issue: GitHub.