microsoft/semantic-kernel · 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

Raised by SerializationRegistry.serialize when no serializer is registered for the exact (type_name, data_content_type) tuple. Note the asymmetry: deserialize returns an UnknownPayload sentinel instead of raising, while serialize raises ValueError. Mismatches in either the type name (class __name__ vs protobuf DESCRIPTOR.full_name) or the content-type string cause a lookup miss.

Source

Thrown at python/semantic_kernel/agents/runtime/core/serialization.py:306

            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:
        """Deserialize a payload into a message."""
        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:
        """Serialize a message into a payload."""
        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:
        """Check if a type is registered in the registry."""
        return (type_name, data_content_type) in self._serializers

    def type_name(self, message: Any) -> str:
        """Get the type name of a message."""
        return _type_name(message)

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Register the serializer before serializing via registry.add_serializer(...).
  2. Ensure type_name matches the serializer's type_name and data_content_type matches exactly (use the library constants).
  3. Check registry.is_registered(type_name, data_content_type) before serializing.
  4. Reuse the runtime's pre-populated registry rather than an empty one.

Example fix

// before
registry = SerializationRegistry()
registry.serialize(msg, type_name='MyMsg', data_content_type='application/json')  # not registered -> ValueError

// after
from semantic_kernel.agents.runtime.core.serialization import PydanticJsonMessageSerializer, JSON_DATA_CONTENT_TYPE
registry.add_serializer(PydanticJsonMessageSerializer(MyMsg))
registry.serialize(msg, type_name='MyMsg', data_content_type=JSON_DATA_CONTENT_TYPE)
Defensive patterns

Strategy: validation

Validate before calling

def can_serialize(registry, type_name: str, data_content_type: str) -> bool:
    return registry.is_registered(type_name, data_content_type)

Try / catch

try:
    payload = registry.serialize(msg, type_name=tn, data_content_type=ct)
except ValueError as e:
    logger.error('Type/content-type not registered: %s', e)

Prevention

When it happens

Trigger: Calling registry.serialize(msg, type_name=..., data_content_type=...) for a pair that was never added via add_serializer; using a content-type string that differs from the serializer's data_content_type (e.g. 'application/json' vs the library constant); a type_name that does not match the serializer's type_name; using a freshly constructed empty registry.

Common situations: Forgetting to register a serializer; reconstructing a registry without re-registering; content-type string drift between producer and consumer; using the class's qualified name instead of __name__.

Related errors


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