{"record":{"id":"5fe52b3e2c7c1231","repo":"microsoft/semantic-kernel","slug":"only-text-and-image-content-are-supported-in-a-use","errorCode":null,"errorMessage":"Only text and image content are supported in a user message.","messagePattern":"Only text and image content are supported in a user message\\.","errorType":"exception","errorClass":"ServiceInvalidRequestError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/bedrock/services/model_provider/utils.py","lineNumber":62,"sourceCode":"    \"\"\"\n    return {\"text\": message.content}\n\n\ndef _format_user_message(message: ChatMessageContent) -> dict[str, Any]:\n    \"\"\"Format a user message to the expected object for the client.\n\n    Note that Guardrails and Documents are currently not supported.\n\n    Args:\n        message: The user message.\n\n    Returns:\n        The formatted user message.\n    \"\"\"\n    contents: list[Any] = []\n    for item in message.items:\n        if not isinstance(item, (ImageContent, TextContent)):\n            raise ServiceInvalidRequestError(\"Only text and image content are supported in a user message.\")\n\n        if isinstance(item, ImageContent):\n            contents.append({\n                \"image\": {\n                    \"format\": item.mime_type.removeprefix(\"image/\"),\n                    \"source\": {\n                        \"bytes\": item.data,\n                    },\n                }\n            })\n        else:\n            contents.append({\"text\": item.text})\n\n    return {\n        \"role\": \"user\",\n        \"content\": contents,\n    }\n","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/bedrock/services/model_provider/utils.py#L44-L80","documentation":"Raised while formatting a user-role ChatMessageContent for Bedrock when an item in message.items is neither TextContent nor ImageContent. The Bedrock user-message converter only supports those two content types; everything else (function calls, function results, annotations, file references) is rejected before the request is sent.","triggerScenarios":"A ChatHistory containing a user message whose items include FunctionCallContent, FunctionResultContent, or any non-text/non-image content type, being sent to a Bedrock chat completion service via _format_user_message.","commonSituations":"Manually constructing a user message with a tool result instead of a tool-role message; replaying a mixed-content assistant/tool history into a user role; loading a chat history from storage that tagged tool results as user role.","solutions":["Assign tool outputs to AuthorRole.TOOL messages, not AuthorRole.USER, so they flow through _format_tool_message.","Strip or convert unsupported items (e.g. FunctionResultContent) from user messages before adding them to ChatHistory.","When replaying history, use the MESSAGE_CONVERTERS mapping so each role is formatted by its dedicated converter."],"exampleFix":"// before\nhistory.add_message(ChatMessageContent(role=AuthorRole.USER, items=[FunctionResultContent(...)]))\n// after\nhistory.add_message(ChatMessageContent(role=AuthorRole.TOOL, items=[FunctionResultContent(...)]))","handlingStrategy":"validation","validationCode":"from semantic_kernel.contents.chat_message_content import ChatMessageContent\nfrom semantic_kernel.contents.image_content import ImageContent\nfrom semantic_kernel.contents.text_content import TextContent\n\ndef user_message_is_bedrock_safe(message: ChatMessageContent) -> bool:\n    return all(isinstance(i, (TextContent, ImageContent)) for i in message.items)","typeGuard":"from semantic_kernel.contents.image_content import ImageContent\nfrom semantic_kernel.contents.text_content import TextContent\n\ndef is_bedrock_user_item(item: object) -> bool:\n    return isinstance(item, (TextContent, 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 \"Only text and image content are supported in a user message\" in str(e):\n        history.messages = [sanitize_for_bedrock(m) for m in history.messages]\n    raise","preventionTips":["Keep user-role messages limited to TextContent and ImageContent.","Route tool outputs to AuthorRole.TOOL, not USER.","Sanitize ChatHistory items by role before sending to Bedrock."],"tags":["bedrock","chat-history","content-types","user-message"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}