microsoft/semantic-kernel · error · ValueError

Unknown metadata type: {type(metadata)}

Error message

Unknown metadata type: {type(metadata)}

What it means

Raised by the telemetry context extractor when the metadata argument is not None, not an EnvelopeMetadata, and lacks __getitem__ (i.e. is not mapping-like). EnvelopeMetadata and __getitem__-supporting objects (such as RemoteCallMetadata) are accepted; None yields an empty Context; anything else raises ValueError.

Source

Thrown at python/semantic_kernel/agents/runtime/core/telemetry/propagation.py:104


@experimental
def get_telemetry_context(metadata: TelemetryMetadataContainer) -> Context:
    """Retrieves the telemetry context from the given metadata.

    Args:
        metadata (Optional[EnvelopeMetadata]): The metadata containing the telemetry context.

    Returns:
        Context: The telemetry context extracted from the metadata, or an empty context if the metadata is None.
    """
    if metadata is None:
        return Context()
    if isinstance(metadata, EnvelopeMetadata):
        return extract(_get_carrier_for_envelope_metadata(metadata))
    if hasattr(metadata, "__getitem__"):
        return extract(_get_carrier_for_remote_call_metadata(metadata))
    raise ValueError(f"Unknown metadata type: {type(metadata)}")


@experimental
def get_telemetry_links(
    metadata: TelemetryMetadataContainer,
) -> Sequence[Link] | None:
    """Retrieves the telemetry links from the given metadata.

    Args:
        metadata (Optional[EnvelopeMetadata]): The metadata containing the telemetry links.

    Returns:
        Optional[Sequence[Link]]: The telemetry links extracted from the metadata, or None if there are no links.
    """
    if metadata is None:
        return None
    if isinstance(metadata, EnvelopeMetadata):
        context = extract(_get_carrier_for_envelope_metadata(metadata))

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Pass an EnvelopeMetadata or a mapping-like object that supports __getitem__.
  2. Pass None when there is no telemetry metadata.
  3. Wrap custom metadata into one of the supported container types before extraction.

Example fix

// before
ctx = extract_telemetry_context(['traceparent: 00-...'])  # list has no __getitem__ semantics here -> ValueError

// after
from semantic_kernel.agents.runtime.core import EnvelopeMetadata
ctx = extract_telemetry_context(EnvelopeMetadata({'traceparent': '00-...'}))
Defensive patterns

Strategy: type-guard

Validate before calling

def is_supported_metadata(m) -> bool:
    from semantic_kernel.agents.runtime.core import EnvelopeMetadata
    return m is None or isinstance(m, EnvelopeMetadata) or hasattr(m, '__getitem__')

Type guard

from semantic_kernel.agents.runtime.core import EnvelopeMetadata

def is_telemetry_metadata(m) -> bool:
    return m is None or isinstance(m, EnvelopeMetadata) or hasattr(m, '__getitem__')

Prevention

When it happens

Trigger: Passing a metadata value that is neither EnvelopeMetadata nor a mapping-like object: a list, tuple, set, int, or a custom object that does not implement __getitem__.

Common situations: Building telemetry calls with an ad-hoc metadata object; passing a primitive or sequence where a metadata container is expected.

Related errors


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