microsoft/semantic-kernel · error · ServiceInvalidRequestError

Unsupported content type in a tool message: {type(item)}

Error message

Unsupported content type in a tool message: {type(item)}

What it means

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.

Source

Thrown at python/semantic_kernel/connectors/ai/bedrock/services/model_provider/utils.py:144

        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,
    }


MESSAGE_CONVERTERS: dict[AuthorRole, Callable[[ChatMessageContent], dict[str, Any]]] = {
    AuthorRole.SYSTEM: _format_system_message,
    AuthorRole.USER: _format_user_message,
    AuthorRole.ASSISTANT: _format_assistant_message,
    AuthorRole.TOOL: _format_tool_message,
}


def update_settings_from_function_choice_configuration(
    function_choice_configuration: "FunctionCallChoiceConfiguration",
    settings: "PromptExecutionSettings",

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Move FunctionCallContent items into an assistant-role message (tool calls belong to the assistant turn).
  2. Use the reported type in the error to identify and remove/redirect the unsupported item.
  3. Restrict tool-role messages to TextContent and FunctionResultContent when targeting Bedrock.

Example fix

// before
history.add_message(ChatMessageContent(role=AuthorRole.TOOL, items=[FunctionCallContent(...)]))
// after
history.add_message(ChatMessageContent(role=AuthorRole.ASSISTANT, items=[FunctionCallContent(...)]))
Defensive patterns

Strategy: validation

Validate before calling

from semantic_kernel.contents.text_content import TextContent
from semantic_kernel.contents.function_result_content import FunctionResultContent

def tool_items_are_bedrock_supported(items) -> bool:
    return all(isinstance(i, (TextContent, FunctionResultContent)) for i in items)

Type guard

from semantic_kernel.contents.text_content import TextContent
from semantic_kernel.contents.function_result_content import FunctionResultContent

def is_bedrock_tool_item(item: object) -> bool:
    return isinstance(item, (TextContent, FunctionResultContent))

Try / catch

from semantic_kernel.exceptions.service_exceptions import ServiceInvalidRequestError

try:
    await service.get_chat_message_contents(history, settings)
except ServiceInvalidRequestError as e:
    if "Unsupported content type in a tool message" in str(e):
        logger.error("Offending item type in tool message; move FunctionCallContent to ASSISTANT role")
    raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/028e8583e104d29d. Report an issue: GitHub.