deepset-ai/haystack · error · TypeError

Error loading pipeline from YAML - Ensure that all pipeline

Error message

Error loading pipeline from YAML - Ensure that all pipeline components only serialize basic Python types

What it means

YamlMarshaller.unmarshal loads YAML back into a dictionary; the YAML must only use constructor tags for basic types. If the YAML contains unknown or unsafe python-specific tags (from another marshaller/version or hand-editing), yaml raises ConstructorError, re-raised as a TypeError with guidance about basic Python types.

Source

Thrown at haystack/marshal/yaml.py:42

YamlLoader.add_constructor("tag:yaml.org,2002:python/tuple", YamlLoader.construct_python_tuple)


class YamlMarshaller:
    def marshal(self, dict_: dict[str, Any]) -> str:
        """Return a YAML representation of the given dictionary."""
        try:
            return yaml.dump(dict_, Dumper=YamlDumper)
        except yaml.representer.RepresenterError as e:
            raise TypeError(
                "Error dumping pipeline to YAML - Ensure that all pipeline components only serialize basic Python types"
            ) from e

    def unmarshal(self, data_: str | bytes | bytearray) -> dict[str, Any]:
        """Return a dictionary from the given YAML data."""
        try:
            return yaml.load(data_, Loader=YamlLoader)
        except yaml.constructor.ConstructorError as e:
            raise TypeError(
                "Error loading pipeline from YAML - Ensure that all pipeline "
                "components only serialize basic Python types"
            ) from e

View on GitHub (pinned to e318778c9b)

Solutions

  1. Regenerate the YAML with the same haystack pipeline's dumps/marshal so it uses supported tags
  2. Remove or replace unsupported tags in the YAML with plain basic-type values
  3. Confirm you are loading YAML (not JSON/marshalled bytes from another marshaller) with the matching loader

Example fix

// before
components:
  cleaner: !!python/object:pipeline.Cleaner {x: 1}  # unsupported tag
// after
components:
  cleaner:
    type: pipeline.Cleaner
    init_parameters: {x: 1}
Defensive patterns

Strategy: try-catch

Validate before calling

import yaml
class NoUnknownTags(yaml.SafeLoader): pass
def check_yaml_tags(data):
    list(yaml.compose(data, Loader=NoUnknownTags))  # raises on unsupported tags

Try / catch

try:
    d = marshaller.unmarshal(data)
except TypeError as e:
    if "loading pipeline from YAML" in str(e):
        d = marshaller.unmarshal(regenerate_yaml(data))  # re-dump with supported tags
    else:
        raise

Prevention

When it happens

Trigger: Calling unmarshal (or pipeline loads) on YAML containing tags YamlLoader cannot construct — e.g. `!!python/object` tags, custom tags emitted by other tools, or corrupted/hand-edited pipeline YAML.

Common situations: Loading YAML produced by a different haystack version or a JSON/YAML dump with custom tags; manually edited pipeline files with stray tags; cross-framework marshalled content pasted into haystack YAML.

Related errors


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