microsoft/semantic-kernel · error · ServiceInvalidRequestError
Unsupported content type in an assistant message: {type(item
Error message
Unsupported content type in an assistant message: {type(item)} What it means
Raised while formatting an assistant-role message for Bedrock when an item is not TextContent, ImageContent (caught above as a specific error), or FunctionCallContent. It is the fallback guard for any unrecognized content type in an assistant turn, reporting the offending Python type in the message.
Source
Thrown at python/semantic_kernel/connectors/ai/bedrock/services/model_provider/utils.py:111
contents: list[Any] = []
for item in message.items:
if isinstance(item, ImageContent):
raise ServiceInvalidRequestError("Image content is not supported in an assistant message.")
if isinstance(item, TextContent):
contents.append({"text": item.text})
elif isinstance(item, FunctionCallContent):
contents.append({
"toolUse": {
"toolUseId": item.id,
"name": item.name,
"input": item.arguments
if isinstance(item.arguments, Mapping)
else json.loads(item.arguments or "{}"),
}
})
else:
raise ServiceInvalidRequestError(f"Unsupported content type in an assistant message: {type(item)}")
return {
"role": "assistant",
"content": contents,
}
def _format_tool_message(message: ChatMessageContent) -> dict[str, Any]:
"""Format a tool message to the expected object for the client.
Args:
message: The tool message.
Returns:
The formatted tool message.
"""
contents: list[Any] = []
for item in message.items:View on GitHub (pinned to c028a0c7dc)
Solutions
- Move FunctionResultContent items to a tool-role message; move annotations/file references out of the assistant turn or strip them before Bedrock serialization.
- Inspect the reported type in the error message to identify exactly which content class triggered it.
- Keep assistant messages limited to TextContent and FunctionCallContent when targeting Bedrock.
Example fix
// before history.add_message(ChatMessageContent(role=AuthorRole.ASSISTANT, items=[FunctionResultContent(...)])) // after history.add_message(ChatMessageContent(role=AuthorRole.TOOL, items=[FunctionResultContent(...)]))
Defensive patterns
Strategy: validation
Validate before calling
from semantic_kernel.contents.text_content import TextContent
from semantic_kernel.contents.function_call_content import FunctionCallContent
def assistant_items_are_bedrock_supported(items) -> bool:
return all(isinstance(i, (TextContent, FunctionCallContent)) for i in items) Type guard
from semantic_kernel.contents.text_content import TextContent
from semantic_kernel.contents.function_call_content import FunctionCallContent
def is_bedrock_assistant_item(item: object) -> bool:
return isinstance(item, (TextContent, FunctionCallContent)) Try / catch
from semantic_kernel.exceptions.service_exceptions import ServiceInvalidRequestError
try:
await service.get_chat_message_contents(history, settings)
except ServiceInvalidRequestError as e:
if "Unsupported content type in an assistant message" in str(e):
logger.error("Offending item type in assistant message; redirect tool results to TOOL role")
raise Prevention
- Restrict assistant messages to TextContent and FunctionCallContent for Bedrock.
- Move FunctionResultContent to tool-role messages.
- Log item types when building assistant messages to catch unsupported content early.
When it happens
Trigger: A ChatHistory assistant message contains a content item such as FunctionResultContent, AnnotationContent, FileReferenceContent, or any future content type not handled by _format_assistant_message.
Common situations: Mixing a tool result into an assistant message; adding annotation/file-reference items to assistant turns; a new content class was introduced in a newer SK version but the Bedrock converter has not been updated.
Related errors
- Image content is not supported in an assistant message.
- Only text and image content are supported in a user message.
- Image content is not supported in a tool message.
- Unsupported content type in a tool message: {type(item)}
- No chat history available.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/99c81711a94b71a9.
Report an issue: GitHub.