microsoft/semantic-kernel · error · ServiceInvalidRequestError
Image content is not supported in a tool message.
Error message
Image content is not supported in a tool message.
What it means
Raised while formatting a tool-role message for Bedrock when an item is an ImageContent. The Bedrock tool-result converter accepts only TextContent and FunctionResultContent; image content in a tool result is explicitly rejected (the code comment notes image/document tool results are not yet supported by SK).
Source
Thrown at python/semantic_kernel/connectors/ai/bedrock/services/model_provider/utils.py:131
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:
if isinstance(item, ImageContent):
raise ServiceInvalidRequestError("Image content is not supported in a tool message.")
if isinstance(item, TextContent):
contents.append({"text": item.text})
elif isinstance(item, FunctionResultContent):
contents.append({
"toolResult": {
"toolUseId": item.id,
# Image and document content are not yet supported in a tool message by SK
"content": [{"text": str(item)}],
}
})
else:
raise ServiceInvalidRequestError(f"Unsupported content type in a tool message: {type(item)}")
return {
"role": "user",
"content": contents,
}View on GitHub (pinned to c028a0c7dc)
Solutions
- Convert image function results to a text representation (e.g. a URL or description) before placing them in a tool message for Bedrock.
- If the function must return binary image data, do not route it through Bedrock tool results; return metadata text instead.
- Filter ImageContent out of tool messages before serialization when targeting Bedrock.
Example fix
// before history.add_message(ChatMessageContent(role=AuthorRole.TOOL, items=[ImageContent(...)])) // after history.add_message(ChatMessageContent(role=AuthorRole.TOOL, items=[TextContent(text=str(image_url))]))
Defensive patterns
Strategy: validation
Validate before calling
from semantic_kernel.contents.image_content import ImageContent
def tool_message_has_no_image(items) -> bool:
return not any(isinstance(i, ImageContent) for i in items) Type guard
from semantic_kernel.contents.image_content import ImageContent
def is_bedrock_safe_tool_item(item: object) -> bool:
return not isinstance(item, ImageContent) Try / catch
from semantic_kernel.exceptions.service_exceptions import ServiceInvalidRequestError
try:
await service.get_chat_message_contents(history, settings)
except ServiceInvalidRequestError as e:
if "Image content is not supported in a tool message" in str(e):
convert_image_tool_results_to_text(history)
raise Prevention
- Return text (URL/description) from plugin functions rather than images for Bedrock tool results.
- Filter ImageContent out of tool messages before serialization.
- Validate tool message items before sending to Bedrock.
When it happens
Trigger: A tool-role ChatMessageContent whose items include an ImageContent is sent through _format_tool_message to a Bedrock chat completion service.
Common situations: A plugin returns an image as its function result and it lands in a tool-role message; deserializing a stored tool message that carried image content; a vision-returning function being auto-invoked during function calling.
Related errors
- Image content is not supported in an assistant message.
- Unsupported content type in a tool message: {type(item)}
- Only text and image content are supported in a user message.
- Unsupported content type in an assistant message: {type(item
- No function result provided in the tool message.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/f7376c0729468242.
Report an issue: GitHub.