{"record":{"id":"028e8583e104d29d","repo":"microsoft/semantic-kernel","slug":"unsupported-content-type-in-a-tool-message-type","errorCode":null,"errorMessage":"Unsupported content type in a tool message: {type(item)}","messagePattern":"Unsupported content type 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":144,"sourceCode":"        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    }\n\n\nMESSAGE_CONVERTERS: dict[AuthorRole, Callable[[ChatMessageContent], dict[str, Any]]] = {\n    AuthorRole.SYSTEM: _format_system_message,\n    AuthorRole.USER: _format_user_message,\n    AuthorRole.ASSISTANT: _format_assistant_message,\n    AuthorRole.TOOL: _format_tool_message,\n}\n\n\ndef update_settings_from_function_choice_configuration(\n    function_choice_configuration: \"FunctionCallChoiceConfiguration\",\n    settings: \"PromptExecutionSettings\",","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/connectors/ai/bedrock/services/model_provider/utils.py#L126-L162","documentation":"Raised while formatting a tool-role message for Bedrock when an item is not TextContent, ImageContent (caught above as a specific error), or FunctionResultContent. It is the fallback guard for any unrecognized content type in a tool turn, reporting the offending Python type.","triggerScenarios":"A tool-role ChatMessageContent contains a content item such as FunctionCallContent, AnnotationContent, FileReferenceContent, or any unhandled content class, sent to a Bedrock chat completion service.","commonSituations":"A function call item mistakenly placed in a tool message instead of an assistant message; annotation/file-reference items attached to tool turns; a newer SK content type not yet handled by the Bedrock tool converter.","solutions":["Move FunctionCallContent items into an assistant-role message (tool calls belong to the assistant turn).","Use the reported type in the error to identify and remove/redirect the unsupported item.","Restrict tool-role messages to TextContent and FunctionResultContent when targeting Bedrock."],"exampleFix":"// before\nhistory.add_message(ChatMessageContent(role=AuthorRole.TOOL, items=[FunctionCallContent(...)]))\n// after\nhistory.add_message(ChatMessageContent(role=AuthorRole.ASSISTANT, items=[FunctionCallContent(...)]))","handlingStrategy":"validation","validationCode":"from semantic_kernel.contents.text_content import TextContent\nfrom semantic_kernel.contents.function_result_content import FunctionResultContent\n\ndef tool_items_are_bedrock_supported(items) -> bool:\n    return all(isinstance(i, (TextContent, FunctionResultContent)) for i in items)","typeGuard":"from semantic_kernel.contents.text_content import TextContent\nfrom semantic_kernel.contents.function_result_content import FunctionResultContent\n\ndef is_bedrock_tool_item(item: object) -> bool:\n    return isinstance(item, (TextContent, FunctionResultContent))","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 a tool message\" in str(e):\n        logger.error(\"Offending item type in tool message; move FunctionCallContent to ASSISTANT role\")\n    raise","preventionTips":["Keep tool-role messages to TextContent and FunctionResultContent for Bedrock.","Move FunctionCallContent into assistant-role messages.","Inspect item types reported in the error to redirect misplaced content."],"tags":["bedrock","chat-history","content-types","tool-message"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}