microsoft/autogen · error · ValueError

Unknown type {type_name} with content type {data_content_typ

Error message

Unknown type {type_name} with content type {data_content_type}

What it means

MessageRegistry.serialize looks up a serializer by the (type_name, data_content_type) pair and raises ValueError when no serializer was registered for that combination. Deserialization is forgiving (returns UnknownPayload), but serialization cannot proceed without a concrete serializer, hence the hard failure.

Source

Thrown at python/packages/autogen-core/src/autogen_core/_serialization.py:250

    def add_serializer(self, serializer: MessageSerializer[Any] | Sequence[MessageSerializer[Any]]) -> None:
        if isinstance(serializer, Sequence):
            for c in serializer:
                self.add_serializer(c)
            return

        self._serializers[(serializer.type_name, serializer.data_content_type)] = serializer

    def deserialize(self, payload: bytes, *, type_name: str, data_content_type: str) -> Any:
        serializer = self._serializers.get((type_name, data_content_type))
        if serializer is None:
            return UnknownPayload(type_name, data_content_type, payload)

        return serializer.deserialize(payload)

    def serialize(self, message: Any, *, type_name: str, data_content_type: str) -> bytes:
        serializer = self._serializers.get((type_name, data_content_type))
        if serializer is None:
            raise ValueError(f"Unknown type {type_name} with content type {data_content_type}")

        return serializer.serialize(message)

    def is_registered(self, type_name: str, data_content_type: str) -> bool:
        return (type_name, data_content_type) in self._serializers

    def type_name(self, message: Any) -> str:
        return _type_name(message)

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Register the serializer on every runtime/process that serializes: runtime.add_message_serializer(PYDANTICJsonMessageSerializer(Task))
  2. Verify the pair with is_registered(type_name, data_content_type) before serializing
  3. Use MessageRegistry.register_message(...).add_serializer(...) consistently so type_name and content type are derived from the same class
  4. After renaming/moving message classes, re-register under the new _type_name output or fix stale string constants

Example fix

# before
await runtime.publish_message(Task(...), topic)  # ValueError: unknown type

# after
runtime.add_message_serializer(PYDANTICJsonMessageSerializer(Task))
await runtime.publish_message(Task(...), topic)
Defensive patterns

Strategy: validation

Validate before calling

def ensure_serializable(registry, type_name: str, content_type: str):
    if not registry.is_registered(type_name, content_type):
        raise RuntimeError(
            f"no serializer for ({type_name}, {content_type}); register before publishing"
        )

Type guard

def message_is_registered(registry, message, content_type: str) -> bool:
    from autogen_core._serialization import _type_name
    return registry.is_registered(_type_name(message), content_type)

Try / catch

try:
    payload = registry.serialize(msg, type_name=T, data_content_type=C)
except ValueError as e:
    if "Unknown type" in str(e):
        registry.add_serializer(...)  # or route to error handling
    else:
        raise

Prevention

When it happens

Trigger: Calling serializer.serialize(message, type_name=T, data_content_type=C) (or publishing/sending a message whose resolved type_name+content_type was never registered) on a runtime whose registry lacks that pair. Common when the content type differs, e.g. message registered as application/json but sent with application/x-protobuf, or the type_name string (module.Class) changed after a refactor/rename.

Common situations: Publishing before add_message_serializer was called (ordering bug, e.g. serializer registered inside an agent constructor that has not run); module renamed so _type_name produces 'newpkg.messages.Task' while the serializer was registered under the old name; mixing PYDANTIC and dataclass serializers with mismatched content types; cross-process setups where only one process registered the serializer.

Related errors


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