microsoft/semantic-kernel · error · TypeError

Unable to transform output message of type {type(output_mess

Error message

Unable to transform output message of type {type(output_message)} to {self.t_out}.

What it means

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.

Source

Thrown at python/semantic_kernel/agents/orchestration/orchestration_base.py:344

        Args:
            output_message (DefaultTypeAlias): The output message to be transformed.

        Returns:
            TOut: The transformed output message.
        """
        if self.t_out == DefaultTypeAlias or self.t_out in get_args(DefaultTypeAlias):
            if isinstance(output_message, ChatMessageContent) or (
                isinstance(output_message, list)
                and all(isinstance(item, ChatMessageContent) for item in output_message)
            ):
                return output_message  # type: ignore[return-value]
            raise TypeError(f"Invalid output message type: {type(output_message)}. Expected {self.t_out}.")

        if isinstance(output_message, ChatMessageContent):
            return self.t_out(**json.loads(output_message.content))  # type: ignore[misc]

        raise TypeError(f"Unable to transform output message of type {type(output_message)} to {self.t_out}.")

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Provide an explicit output_transform for the orchestration that returns self.t_out directly, bypassing the default typed transform.
  2. Ensure the last actor in the pipeline emits a single ChatMessageContent whose content is valid JSON matching t_out's schema.
  3. If the value is already a t_out instance, return it from your transform so the default transform is not invoked.
  4. Debug by printing type(output_message) and adjust the producing component to emit ChatMessageContent.

Example fix

// before
orch = Sequential[
    str,
    MyModel,
](agents=[...])   # default transform expects ChatMessageContent
// after
orch = Sequential[
    str,
    MyModel,
](
    agents=[...],
    output_transform=lambda out: MyModel.model_validate_json(out.content),
)
Defensive patterns

Strategy: validation

Validate before calling

from semantic_kernel.contents import ChatMessageContent

def can_default_transform(output, t_out) -> bool:
    return isinstance(output, ChatMessageContent) or output is None and False

Type guard

from typing import Any
from semantic_kernel.contents import ChatMessageContent

def is_chat_content(value: Any) -> bool:
    return isinstance(value, ChatMessageContent)

Try / catch

try:
    out = await orchestration.invoke(...)
except TypeError as e:
    if "Unable to transform output message" in str(e):
        # provide an explicit output_transform that constructs t_out
        raise
    raise

Prevention

When it happens

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

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

Related errors


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