{"record":{"id":"99c81711a94b71a9","repo":"microsoft/semantic-kernel","slug":"unsupported-content-type-in-an-assistant-message","errorCode":null,"errorMessage":"Unsupported content type in an assistant message: {type(item)}","messagePattern":"Unsupported content type in an assistant message: (.+?)","errorType":"exception","errorClass":"ServiceInvalidRequestError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/connectors/ai/bedrock/services/model_provider/utils.py","lineNumber":111,"sourceCode":"    contents: list[Any] = []\n    for item in message.items:\n        if isinstance(item, ImageContent):\n            raise ServiceInvalidRequestError(\"Image content is not supported in an assistant message.\")\n\n        if isinstance(item, TextContent):\n            contents.append({\"text\": item.text})\n        elif isinstance(item, FunctionCallContent):\n            contents.append({\n                \"toolUse\": {\n                    \"toolUseId\": item.id,\n                    \"name\": item.name,\n                    \"input\": item.arguments\n                    if isinstance(item.arguments, Mapping)\n                    else json.loads(item.arguments or \"{}\"),\n                }\n            })\n        else:\n            raise ServiceInvalidRequestError(f\"Unsupported content type in an assistant message: {type(item)}\")\n\n    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:","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/bedrock/services/model_provider/utils.py#L93-L129","documentation":"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.","triggerScenarios":"A ChatHistory assistant message contains a content item such as FunctionResultContent, AnnotationContent, FileReferenceContent, or any future content type not handled by _format_assistant_message.","commonSituations":"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.","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."],"exampleFix":"// before\nhistory.add_message(ChatMessageContent(role=AuthorRole.ASSISTANT, items=[FunctionResultContent(...)]))\n// after\nhistory.add_message(ChatMessageContent(role=AuthorRole.TOOL, items=[FunctionResultContent(...)]))","handlingStrategy":"validation","validationCode":"from semantic_kernel.contents.text_content import TextContent\nfrom semantic_kernel.contents.function_call_content import FunctionCallContent\n\ndef assistant_items_are_bedrock_supported(items) -> bool:\n    return all(isinstance(i, (TextContent, FunctionCallContent)) for i in items)","typeGuard":"from semantic_kernel.contents.text_content import TextContent\nfrom semantic_kernel.contents.function_call_content import FunctionCallContent\n\ndef is_bedrock_assistant_item(item: object) -> bool:\n    return isinstance(item, (TextContent, FunctionCallContent))","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 \"Unsupported content type in an assistant message\" in str(e):\n        logger.error(\"Offending item type in assistant message; redirect tool results to TOOL role\")\n    raise","preventionTips":["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."],"tags":["bedrock","chat-history","content-types","assistant-message"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}