microsoft/autogen · error · ValueError
Unknown content type: {part}
Error message
Unknown content type: {part} What it means
In _ollama_client.py's message conversion, each part of a list-content user message must be either a str or an autogen_core Image. Any other object (float, dict, a different image class, None) hits the else and raises ValueError with the offending part. The check is per-part, so a single bad element poisons the whole message.
Source
Thrown at python/packages/autogen-ext/src/autogen_ext/models/ollama/_ollama_client.py:187
# name=message.source, # TODO: No name parameter in Ollama
)
]
else:
ollama_messages: List[Message] = []
for part in message.content:
if isinstance(part, str):
ollama_messages.append(Message(content=part, role="user"))
elif isinstance(part, Image):
# TODO: should images go into their own message? Should each image get its own message?
if not ollama_messages:
ollama_messages.append(Message(role="user", images=[OllamaImage(value=part.to_base64())]))
else:
if ollama_messages[-1].images is None:
ollama_messages[-1].images = [OllamaImage(value=part.to_base64())]
else:
ollama_messages[-1].images.append(OllamaImage(value=part.to_base64())) # type: ignore
else:
raise ValueError(f"Unknown content type: {part}")
return ollama_messages
def system_message_to_ollama(message: SystemMessage) -> Message:
return Message(
content=message.content,
role="system",
)
def _func_args_to_ollama_args(args: str) -> Dict[str, Any]:
return json.loads(args) # type: ignore
def func_call_to_ollama(message: FunctionCall) -> Message.ToolCall:
return Message.ToolCall(
function=Message.ToolCall.Function(
name=message.name,View on GitHub (pinned to 027ecf0a37)
Solutions
- Wrap binary images with autogen_core Image: Image.from_pil(pil_img) or Image.from_file('x.png')
- Filter/normalize parts before sending: keep only str and Image instances
- Replace OpenAI-style part dicts with the corresponding str/Image values
Example fix
# before
content = ["describe", {"type": "image_url", "image_url": {"url": uri}}]
msg = UserMessage(content=content, source="user")
# after
from autogen_core.models import Image
content = ["describe", Image.from_file(image_path)]
msg = UserMessage(content=content, source="user") Defensive patterns
Strategy: validation
Validate before calling
from autogen_core.models import Image
def sanitize_parts(parts: Sequence[object]) -> list[str | Image]:
out: list[str | Image] = []
for p in parts:
if isinstance(p, (str, Image)):
out.append(p)
else:
raise TypeError(f"Unsupported content part: {type(p)!r}")
return out
msg = UserMessage(content=sanitize_parts(raw_parts), source="user") Type guard
def is_valid_content_part(p: object) -> TypeGuard[str | Image]:
return isinstance(p, (str, Image)) Try / catch
try:
result = await client.create([msg])
except ValueError as e:
if "Unknown content type" in str(e):
msg = UserMessage(content=[p for p in msg.content if is_valid_content_part(p)], source="user")
result = await client.create([msg])
else:
raise Prevention
- Always construct image parts with autogen_core Image.from_pil/from_file, never raw dicts or PIL objects
- Filter content lists at the boundary of your message-builder module
- Add a unit test that every emitted message part is str or Image
When it happens
Trigger: UserMessage(content=['hi', 123]) or content=['text', {'type': 'image_url', ...}] (raw OpenAI-style part dicts); mixing in a PIL.Image or numpy array instead of autogen_core.models.Image; None entries from conditional part building.
Common situations: Translating OpenAI multi-part format directly instead of using Image.from_pil()/from_file; building content lists with appends that sometimes append falsy/None; a different library's Image type leaking into the message.
Related errors
- Model does not support vision and image was provided
- Multi-part messages such as those containing images are curr
- Model does not support vision and image was provided
- Invalid aggregate message {reason}
- The from field must be null or the agent name
AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15).
Data as JSON: /api/errors/c726d3bbe979b47d.
Report an issue: GitHub.