{"record":{"id":"e9eb6fe12ba4b9a5","repo":"microsoft/semantic-kernel","slug":"invalid-message-body-type-type-message-body-e-e9eb6f","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/handoffs.py","lineNumber":260,"sourceCode":"            await self._result_callback(\n                ChatMessageContent(\n                    role=AuthorRole.ASSISTANT,\n                    name=self._agent.name,\n                    content=f\"Task is completed with summary: {task_summary}\",\n                )\n            )\n        self._task_completed = True\n\n    @message_handler\n    async def _handle_start_message(self, message: HandoffStartMessage, cts: MessageContext) -> None:\n        logger.debug(f\"{self.id}: Received handoff 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: HandoffResponseMessage, cts: MessageContext) -> None:\n        \"\"\"Handle a response message from an agent in the handoff group.\"\"\"\n        logger.debug(f\"{self.id}: Received handoff response message.\")\n        self._message_cache.add_message(message.body)\n\n    @message_handler\n    async def _handle_request_message(self, message: HandoffRequestMessage, cts: MessageContext) -> None:\n        \"\"\"Handle a request message from an agent in the handoff group.\"\"\"\n        if message.agent_name != self._agent.name:\n            return\n        logger.debug(f\"{self.id}: Received handoff request message.\")\n\n        response = await self._invoke_agent_with_potentially_no_response(kernel=self._kernel)\n\n        while not self._task_completed:\n            if self._handoff_agent_name:","sourceCodeStart":242,"sourceCodeEnd":278,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/orchestration/handoffs.py#L242-L278","documentation":"Raised as a ValueError in HandoffActor._handle_start_message when the incoming HandoffStartMessage.body is neither a ChatMessageContent nor a list of ChatMessageContent. The handoff actor caches the initial messages before invoking its agent, and requires the DefaultTypeAlias shape; anything else is rejected.","triggerScenarios":"A HandoffStartMessage is published with a body that is not a ChatMessageContent or list thereof. Stems from a custom input_transform on HandoffOrchestration returning the wrong type, or feeding raw strings/other objects into the orchestration.","commonSituations":"input_transform returns a raw string/dict instead of ChatMessageContent; passing a string into orchestration.invoke; version drift changing the expected message type; manually constructing a HandoffStartMessage with an invalid body.","solutions":["Ensure input_transform returns ChatMessageContent or list[ChatMessageContent].","Wrap raw input strings into ChatMessageContent(role=AuthorRole.USER, content=...) before invoking.","Match the DefaultTypeAlias shape required by the installed SK version.","Do not publish HandoffStartMessage with an arbitrary body type."],"exampleFix":"# before\nresult = await handoff_orchestration.invoke(\"please summarize\")  # may produce wrong body\n# after\nresult = await handoff_orchestration.invoke(\n    [ChatMessageContent(role=AuthorRole.USER, content=\"please summarize\")],\n    runtime=runtime,\n)","handlingStrategy":"type-guard","validationCode":"# Normalize orchestration input to the expected type before invoking:\nfrom semantic_kernel.contents import ChatMessageContent, AuthorRole\ndef normalize(inp):\n    if isinstance(inp, str):\n        return [ChatMessageContent(role=AuthorRole.USER, content=inp)]\n    return inp","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 handoff_orchestration.invoke(messages, runtime=runtime)\nexcept ValueError as ex:\n    if \"Invalid message body type\" in str(ex):\n        messages = normalize(messages)\n        result = await handoff_orchestration.invoke(messages, runtime=runtime)","preventionTips":["Wrap raw strings into ChatMessageContent before invoking a handoff orchestration.","Ensure input_transform returns ChatMessageContent or list thereof.","Add a type-check helper at the call boundary."],"tags":["orchestration","handoff","validation","message-type"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}