deepset-ai/haystack · error · DeserializationError

Missing 'type' in serialization data

Error message

Missing 'type' in serialization data

What it means

default_from_dict() requires the serialized dict to include a 'type' key identifying the class to instantiate. When the key is absent, Haystack cannot determine which component class to build and raises DeserializationError. Every Haystack serialized object embeds its fully-qualified class name under 'type'.

Source

Thrown at haystack/core/serialization.py:299

    qualified class name are automatically detected and deserialized if the class has a
    `from_dict()` method.

    :param cls:
        The class to be used for deserialization.
    :param data:
        The serialized data.
    :returns:
        The deserialized object.

    :raises DeserializationError:
        If the `type` field in `data` is missing or it doesn't match the type of `cls`.
    """
    # Copy so that replacing serialized sub-objects (Secret/ComponentDevice/nested components) with their
    # deserialized instances below does not mutate the caller's ``data`` dict in place. Without this, a second
    # deserialization of the same dict would receive already-parsed objects instead of their serialized form.
    init_params = dict(data.get("init_parameters", {}))
    if "type" not in data:
        raise DeserializationError("Missing 'type' in serialization data")
    if data["type"] != generate_qualified_class_name(cls):
        raise DeserializationError(f"Class '{data['type']}' can't be deserialized as '{cls.__name__}'")

    valid_init_param_names = _init_parameter_names(cls)

    # Automatically detect and deserialize objects with from_dict methods
    for key, value in init_params.items():
        if isinstance(value, dict) and "type" in value:
            type_value = value.get("type")
            # Special handling for Secret (type == "env_var")
            if type_value == "env_var":
                init_params[key] = Secret.from_dict(value)
            # Special handling for ComponentDevice (type == "single" or "multiple")
            elif _is_serialized_component_device(value):
                init_params[key] = ComponentDevice.from_dict(value)
            # If type looks like a fully qualified class name, try to import it and deserialize
            elif isinstance(type_value, str) and "." in type_value:
                # Reject before importing if the parent class does not accept this parameter.

View on GitHub (pinned to e318778c9b)

Solutions

  1. Add the missing 'type' key with the fully-qualified class name, e.g. 'haystack.components.retrievers.in_memory.InMemoryEmbeddingRetriever'.
  2. Re-export the pipeline from the working environment with pipeline.dumps() and use that output.
  3. Validate the YAML/JSON structure before loading.
  4. Check you are loading the correct file (not a fragment).

Example fix

// before
{"init_parameters": {"sparse_embedding_model": "bm25"}}

// after
{"type": "haystack.components.retrievers.in_memory.InMemoryEmbeddingRetriever", "init_parameters": {"sparse_embedding_model": "bm25"}}
Defensive patterns

Strategy: validation

Validate before calling

def ensure_typed(obj: dict) -> bool:
    if not isinstance(obj, dict):
        return False
    if "type" not in obj:
        return False
    return all(ensure_typed(v) for v in obj.values() if isinstance(v, dict) and "init_parameters" not in v) or True
# simpler: assert "type" in data before calling from_dict

Type guard

def is_typed_component_dict(d: object) -> bool:
    return isinstance(d, dict) and isinstance(d.get("type"), str) and d.get("type", "") != ""

Try / catch

from haystack.core.errors import DeserializationError
try:
    comp = SomeComponent.from_dict(data)
except DeserializationError as e:
    if "Missing 'type'" in str(e):
        data["type"] = "fully.qualified.ComponentName"
        comp = SomeComponent.from_dict(data)

Prevention

When it happens

Trigger: Calling component.from_dict({}) or Pipeline.loads() on hand-written or truncated YAML/JSON where the top-level mapping or an init_parameters entry lacks 'type'.

Common situations: Hand-editing pipeline YAML and deleting the type line; external tools generating pipeline configs; loading files produced by a different format or older tooling.

Related errors


AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30). Data as JSON: /api/errors/3f66d8cea460ca20. Report an issue: GitHub.