microsoft/autogen · error · ValueError

Unknown content type: {message.content}

Error message

Unknown content type: {message.content}

What it means

Raised by _user_message_to_azure in the Azure AI (Foundry / GitHub Models) chat client while converting autogen LLMMessage content to Azure SDK ContentItem objects. When message.content is a list, every element must be a str or an autogen_core.models.Image (sent as ImageContentItem with its data_uri); anything else raises ValueError('Unknown content type: ...'). The message in the f-string prints the whole content object, not the offending part.

Source

Thrown at python/packages/autogen-ext/src/autogen_ext/models/azure/_azure_ai_client.py:130

def _system_message_to_azure(message: SystemMessage) -> AzureSystemMessage:
    return AzureSystemMessage(content=message.content)


def _user_message_to_azure(message: UserMessage) -> AzureUserMessage:
    assert_valid_name(message.source)
    if isinstance(message.content, str):
        return AzureUserMessage(content=message.content)
    else:
        parts: List[ContentItem] = []
        for part in message.content:
            if isinstance(part, str):
                parts.append(TextContentItem(text=part))
            elif isinstance(part, Image):
                # TODO: support url based images
                # TODO: support specifying details
                parts.append(ImageContentItem(image_url=ImageUrl(url=part.data_uri, detail=ImageDetailLevel.AUTO)))
            else:
                raise ValueError(f"Unknown content type: {message.content}")
        return AzureUserMessage(content=parts)


def _assistant_message_to_azure(message: AssistantMessage) -> AzureAssistantMessage:
    assert_valid_name(message.source)
    if isinstance(message.content, list):
        return AzureAssistantMessage(
            tool_calls=[_func_call_to_azure(x) for x in message.content],
        )
    else:
        return AzureAssistantMessage(content=message.content)


def _tool_message_to_azure(message: FunctionExecutionResultMessage) -> Sequence[AzureToolMessage]:
    return [AzureToolMessage(content=x.content, tool_call_id=x.call_id) for x in message.content]


def to_azure_message(message: LLMMessage) -> Sequence[AzureMessage]:

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Sanitize the message history before sending: keep only str parts and autogen_core.models.Image parts in UserMessage.content lists
  2. Move tool-call results into FunctionExecutionResultMessage instead of UserMessage content
  3. Verify autogen-core and autogen-ext versions match so the Image class identity used in the isinstance check is the one your code imports

Example fix

# before
msg = UserMessage(content=["describe", some_dict, Image.from_file("a.png")], source="user")

# after
from autogen_core.models import UserMessage, Image
msg = UserMessage(
    content=[p for p in ["describe", some_dict, Image.from_file("a.png")] if isinstance(p, (str, Image))],
    source="user",
)
Defensive patterns

Strategy: type-guard

Validate before calling

from autogen_core.models import UserMessage, Image

def content_is_azure_safe(content) -> bool:
    if isinstance(content, str):
        return True
    return all(isinstance(p, (str, Image)) for p in content)

Type guard

from autogen_core.models import Image
from typing import Union, List

AzureSafePart = Union[str, Image]

def is_azure_safe_part(part) -> bool:
    return isinstance(part, (str, Image))

Try / catch

try:
    result = await client.create(msgs)
except ValueError as e:
    if str(e).startswith("Unknown content type"):
        msgs = [strip_unsupported_parts(m) for m in msgs]  # keep only str/Image
        result = await client.create(msgs)
    else:
        raise

Prevention

When it happens

Trigger: Calling AzureAIChatCompletionClient.create()/create_stream() with a UserMessage whose content list contains a non-str/non-Image item, e.g. a FunctionCall, a dict, a ToolCallPart, or a multimodal part from another vendor client pasted into the conversation.

Common situations: Reusing a multimodal message history produced by a different model client (e.g. OpenAIChatCompletionClient chunks) with the Azure AI client; mixing tool-call parts into UserMessage content; passing Image from a stale autogen-core version so the isinstance check fails.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/2b50bc03fe0906de. Report an issue: GitHub.