{"record":{"id":"3897bec3f82fe3d3","repo":"microsoft/semantic-kernel","slug":"unable-to-transform-output-message-of-type-type-o","errorCode":null,"errorMessage":"Unable to transform output message of type {type(output_message)} to {self.t_out}.","messagePattern":"Unable to transform output message of type (.+?) to (.+?)\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/orchestration/orchestration_base.py","lineNumber":344,"sourceCode":"\n        Args:\n            output_message (DefaultTypeAlias): The output message to be transformed.\n\n        Returns:\n            TOut: The transformed output message.\n        \"\"\"\n        if self.t_out == DefaultTypeAlias or self.t_out in get_args(DefaultTypeAlias):\n            if isinstance(output_message, ChatMessageContent) or (\n                isinstance(output_message, list)\n                and all(isinstance(item, ChatMessageContent) for item in output_message)\n            ):\n                return output_message  # type: ignore[return-value]\n            raise TypeError(f\"Invalid output message type: {type(output_message)}. Expected {self.t_out}.\")\n\n        if isinstance(output_message, ChatMessageContent):\n            return self.t_out(**json.loads(output_message.content))  # type: ignore[misc]\n\n        raise TypeError(f\"Unable to transform output message of type {type(output_message)} to {self.t_out}.\")\n","sourceCodeStart":326,"sourceCodeEnd":345,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/orchestration/orchestration_base.py#L326-L345","documentation":"Raised by _default_output_transform's typed branch when t_out is a concrete target type (not the default alias) but the internal output_message is not a ChatMessageContent, so the transform cannot json.loads its content and construct t_out. The typed branch only knows how to deserialize a ChatMessageContent.content string into t_out; any other runtime object cannot be converted.","triggerScenarios":"Declaring a structured output type (e.g. t_out=MyModel) so the orchestration takes the typed branch, but an upstream agent or transform emits a list of ChatMessageContent or a pydantic object instead of a single ChatMessageContent whose .content is JSON. The branch `if isinstance(output_message, ChatMessageContent)` fails and execution falls through to this raise.","commonSituations":"Using a custom output_transform that returns the model already-constructed instead of ChatMessageContent; a sequential/group orchestration whose last agent returns a list while t_out expects a single typed object; JSON content that failed to parse earlier and was replaced by a placeholder object.","solutions":["Provide an explicit output_transform for the orchestration that returns self.t_out directly, bypassing the default typed transform.","Ensure the last actor in the pipeline emits a single ChatMessageContent whose content is valid JSON matching t_out's schema.","If the value is already a t_out instance, return it from your transform so the default transform is not invoked.","Debug by printing type(output_message) and adjust the producing component to emit ChatMessageContent."],"exampleFix":"// before\norch = Sequential[\n    str,\n    MyModel,\n](agents=[...])   # default transform expects ChatMessageContent\n// after\norch = Sequential[\n    str,\n    MyModel,\n](\n    agents=[...],\n    output_transform=lambda out: MyModel.model_validate_json(out.content),\n)","handlingStrategy":"validation","validationCode":"from semantic_kernel.contents import ChatMessageContent\n\ndef can_default_transform(output, t_out) -> bool:\n    return isinstance(output, ChatMessageContent) or output is None and False","typeGuard":"from typing import Any\nfrom semantic_kernel.contents import ChatMessageContent\n\ndef is_chat_content(value: Any) -> bool:\n    return isinstance(value, ChatMessageContent)","tryCatchPattern":"try:\n    out = await orchestration.invoke(...)\nexcept TypeError as e:\n    if \"Unable to transform output message\" in str(e):\n        # provide an explicit output_transform that constructs t_out\n        raise\n    raise","preventionTips":["For structured t_out, always pass an explicit output_transform.","Ensure the last agent returns a single ChatMessageContent with JSON content.","Do not reuse the default typed transform when upstream already returns the target model.","Log type(output_message) before wiring transforms to catch mismatches early."],"tags":["orchestration","type-mismatch","message-transform","semantic-kernel"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}