{"record":{"id":"f7376c0729468242","repo":"microsoft/semantic-kernel","slug":"image-content-is-not-supported-in-a-tool-message","errorCode":null,"errorMessage":"Image content is not supported in a tool message.","messagePattern":"Image content is not supported in a tool message\\.","errorType":"exception","errorClass":"ServiceInvalidRequestError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/bedrock/services/model_provider/utils.py","lineNumber":131,"sourceCode":"    return {\n        \"role\": \"assistant\",\n        \"content\": contents,\n    }\n\n\ndef _format_tool_message(message: ChatMessageContent) -> dict[str, Any]:\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    contents: list[Any] = []\n    for item in message.items:\n        if isinstance(item, ImageContent):\n            raise ServiceInvalidRequestError(\"Image content is not supported in a tool message.\")\n\n        if isinstance(item, TextContent):\n            contents.append({\"text\": item.text})\n        elif isinstance(item, FunctionResultContent):\n            contents.append({\n                \"toolResult\": {\n                    \"toolUseId\": item.id,\n                    # Image and document content are not yet supported in a tool message by SK\n                    \"content\": [{\"text\": str(item)}],\n                }\n            })\n        else:\n            raise ServiceInvalidRequestError(f\"Unsupported content type in a tool message: {type(item)}\")\n\n    return {\n        \"role\": \"user\",\n        \"content\": contents,\n    }","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/bedrock/services/model_provider/utils.py#L113-L149","documentation":"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).","triggerScenarios":"A tool-role ChatMessageContent whose items include an ImageContent is sent through _format_tool_message to a Bedrock chat completion service.","commonSituations":"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.","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."],"exampleFix":"// before\nhistory.add_message(ChatMessageContent(role=AuthorRole.TOOL, items=[ImageContent(...)]))\n// after\nhistory.add_message(ChatMessageContent(role=AuthorRole.TOOL, items=[TextContent(text=str(image_url))]))","handlingStrategy":"validation","validationCode":"from semantic_kernel.contents.image_content import ImageContent\n\ndef tool_message_has_no_image(items) -> bool:\n    return not any(isinstance(i, ImageContent) for i in items)","typeGuard":"from semantic_kernel.contents.image_content import ImageContent\n\ndef is_bedrock_safe_tool_item(item: object) -> bool:\n    return not isinstance(item, ImageContent)","tryCatchPattern":"from semantic_kernel.exceptions.service_exceptions import ServiceInvalidRequestError\n\ntry:\n    await service.get_chat_message_contents(history, settings)\nexcept ServiceInvalidRequestError as e:\n    if \"Image content is not supported in a tool message\" in str(e):\n        convert_image_tool_results_to_text(history)\n    raise","preventionTips":["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."],"tags":["bedrock","chat-history","content-types","tool-message","image"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}