microsoft/semantic-kernel · error · ValueError

Invalid message body type: {type(message.body)}. Expected {D

Error message

Invalid message body type: {type(message.body)}. Expected {DefaultTypeAlias}.

What it means

Raised as a ValueError in GroupChatAgentActor._handle_start_message when the incoming GroupChatStartMessage.body is neither a ChatMessageContent nor a list of ChatMessageContent. The group-chat actor expects the start payload to follow the DefaultTypeAlias (ChatMessageContent | list[ChatMessageContent]); any other type is rejected before being added to the message cache.

Source

Thrown at python/semantic_kernel/agents/orchestration/group_chat.py:115

# region GroupChatAgentActor


@experimental
class GroupChatAgentActor(AgentActorBase):
    """An agent actor that process messages in a group chat."""

    @message_handler
    async def _handle_start_message(self, message: GroupChatStartMessage, ctx: MessageContext) -> None:
        """Handle the start message for the group chat."""
        logger.debug(f"{self.id}: Received group chat start message.")
        if isinstance(message.body, ChatMessageContent):
            self._message_cache.add_message(message.body)
        elif isinstance(message.body, list) and all(isinstance(m, ChatMessageContent) for m in message.body):
            for m in message.body:
                self._message_cache.add_message(m)
        else:
            raise ValueError(f"Invalid message body type: {type(message.body)}. Expected {DefaultTypeAlias}.")

    @message_handler
    async def _handle_response_message(self, message: GroupChatResponseMessage, ctx: MessageContext) -> None:
        logger.debug(f"{self.id}: Received group chat response message.")
        self._message_cache.add_message(message.body)

    @message_handler
    async def _handle_request_message(self, message: GroupChatRequestMessage, ctx: MessageContext) -> None:
        if message.agent_name != self._agent.name:
            return

        logger.debug(f"{self.id}: Received group chat request message.")

        response = await self._invoke_agent()

        logger.debug(f"{self.id} responded with {response}.")

        await self.publish_message(

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Ensure input_transform / the invoke input produces a ChatMessageContent or list[ChatMessageContent].
  2. Wrap raw strings before invoking: ChatMessageContent(role=AuthorRole.USER, content="...").
  3. Check the DefaultTypeAlias the orchestration expects and match it exactly.
  4. If subclassing, do not publish a GroupChatStartMessage with an arbitrary body type.

Example fix

# before
result = await orchestration.invoke("hello", runtime=runtime)  # may produce wrong body type
# after - pass a properly typed message
from semantic_kernel.contents import ChatMessageContent, AuthorRole
result = await orchestration.invoke(
    [ChatMessageContent(role=AuthorRole.USER, content="hello")],
    runtime=runtime,
)
Defensive patterns

Strategy: type-guard

Validate before calling

# Ensure the orchestration input is correctly typed before invoking:
from semantic_kernel.contents import ChatMessageContent
def to_messages(inp):
    if isinstance(inp, ChatMessageContent):
        return [inp]
    if isinstance(inp, list) and all(isinstance(m, ChatMessageContent) for m in inp):
        return inp
    raise TypeError("Pass ChatMessageContent or list[ChatMessageContent]")

Type guard

from semantic_kernel.contents import ChatMessageContent
def is_valid_body(body) -> bool:
    if isinstance(body, ChatMessageContent):
        return True
    return isinstance(body, list) and all(isinstance(m, ChatMessageContent) for m in body)

Try / catch

try:
    result = await orchestration.invoke(messages, runtime=runtime)
except ValueError as ex:
    if "Invalid message body type" in str(ex):
        messages = to_messages(messages)  # normalize and retry

Prevention

When it happens

Trigger: A GroupChatStartMessage is published whose body is an unsupported type (e.g. a plain string, a dict, or a different content type). This typically comes from a custom input_transform on GroupChatOrchestration returning the wrong type, or manually publishing a malformed start message.

Common situations: A custom input_transform returns a raw string or dict instead of ChatMessageContent; passing a string directly into orchestration.invoke instead of wrapping it; type drift between orchestration versions; mixing message types from different SK versions.

Related errors


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