{"record":{"id":"fdc57aa50b42fe64","repo":"microsoft/semantic-kernel","slug":"invalid-message-body-type-type-message-body-e","errorCode":null,"errorMessage":"Invalid message body type: {type(message.body)}. Expected {DefaultTypeAlias}.","messagePattern":"Invalid message body type: (.+?)\\. Expected (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/orchestration/group_chat.py","lineNumber":115,"sourceCode":"\n# region GroupChatAgentActor\n\n\n@experimental\nclass GroupChatAgentActor(AgentActorBase):\n    \"\"\"An agent actor that process messages in a group chat.\"\"\"\n\n    @message_handler\n    async def _handle_start_message(self, message: GroupChatStartMessage, ctx: MessageContext) -> None:\n        \"\"\"Handle the start message for the group chat.\"\"\"\n        logger.debug(f\"{self.id}: Received group chat start message.\")\n        if isinstance(message.body, ChatMessageContent):\n            self._message_cache.add_message(message.body)\n        elif isinstance(message.body, list) and all(isinstance(m, ChatMessageContent) for m in message.body):\n            for m in message.body:\n                self._message_cache.add_message(m)\n        else:\n            raise ValueError(f\"Invalid message body type: {type(message.body)}. Expected {DefaultTypeAlias}.\")\n\n    @message_handler\n    async def _handle_response_message(self, message: GroupChatResponseMessage, ctx: MessageContext) -> None:\n        logger.debug(f\"{self.id}: Received group chat response message.\")\n        self._message_cache.add_message(message.body)\n\n    @message_handler\n    async def _handle_request_message(self, message: GroupChatRequestMessage, ctx: MessageContext) -> None:\n        if message.agent_name != self._agent.name:\n            return\n\n        logger.debug(f\"{self.id}: Received group chat request message.\")\n\n        response = await self._invoke_agent()\n\n        logger.debug(f\"{self.id} responded with {response}.\")\n\n        await self.publish_message(","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/orchestration/group_chat.py#L97-L133","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure input_transform / the invoke input produces a ChatMessageContent or list[ChatMessageContent].","Wrap raw strings before invoking: ChatMessageContent(role=AuthorRole.USER, content=\"...\").","Check the DefaultTypeAlias the orchestration expects and match it exactly.","If subclassing, do not publish a GroupChatStartMessage with an arbitrary body type."],"exampleFix":"# before\nresult = await orchestration.invoke(\"hello\", runtime=runtime)  # may produce wrong body type\n# after - pass a properly typed message\nfrom semantic_kernel.contents import ChatMessageContent, AuthorRole\nresult = await orchestration.invoke(\n    [ChatMessageContent(role=AuthorRole.USER, content=\"hello\")],\n    runtime=runtime,\n)","handlingStrategy":"type-guard","validationCode":"# Ensure the orchestration input is correctly typed before invoking:\nfrom semantic_kernel.contents import ChatMessageContent\ndef to_messages(inp):\n    if isinstance(inp, ChatMessageContent):\n        return [inp]\n    if isinstance(inp, list) and all(isinstance(m, ChatMessageContent) for m in inp):\n        return inp\n    raise TypeError(\"Pass ChatMessageContent or list[ChatMessageContent]\")","typeGuard":"from semantic_kernel.contents import ChatMessageContent\ndef is_valid_body(body) -> bool:\n    if isinstance(body, ChatMessageContent):\n        return True\n    return isinstance(body, list) and all(isinstance(m, ChatMessageContent) for m in body)","tryCatchPattern":"try:\n    result = await orchestration.invoke(messages, runtime=runtime)\nexcept ValueError as ex:\n    if \"Invalid message body type\" in str(ex):\n        messages = to_messages(messages)  # normalize and retry","preventionTips":["Always wrap raw strings into ChatMessageContent before invoking.","Ensure input_transform returns ChatMessageContent or list thereof.","Add a type-check helper in your call site."],"tags":["orchestration","group-chat","validation","message-type"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}