High severity intermediate · Fix: 5-10 min

yaml.YAMLError

yaml.YAMLError

What this error means
Haystack raises a yaml.YAMLError when saving or loading a pipeline due to invalid or unsupported YAML serialization of pipeline components.

Stack trace

traceback
yaml.YAMLError: while parsing a block mapping
  in "<unicode string>", line 10, column 3:
    - name: document_store
      ^
found unhashable type: 'dict'
QUICK FIX
Use Haystack's built-in pipeline save/load methods without manual YAML edits and ensure all components are YAML serializable.

Why it happens

Haystack pipelines serialize their configuration to YAML for saving and loading. This error occurs when the pipeline contains components or parameters that are not serializable to YAML, such as complex Python objects or unsupported data types. It often happens if custom components or nested dictionaries are included without proper serialization support.

Detection

Monitor pipeline save/load operations and catch yaml.YAMLError exceptions; log the pipeline config content before serialization to identify problematic fields.

Causes & fixes

1

Pipeline contains custom components or parameters that are not YAML serializable (e.g., complex objects, functions).

✓ Fix

Ensure all pipeline components and parameters are serializable primitives or implement custom serialization methods before saving.

2

Using nested dictionaries or lists with unsupported data types inside pipeline config.

✓ Fix

Flatten or convert nested structures to YAML-compatible types like strings, ints, lists, or dicts with primitive values.

3

Incorrect manual editing of pipeline YAML file introducing syntax errors or invalid structures.

✓ Fix

Validate YAML syntax with a linter or YAML parser before loading; avoid manual edits or use Haystack APIs to modify pipelines.

Code: broken vs fixed

Broken - triggers the error
python
from haystack import Pipeline

pipeline = Pipeline()
pipeline.add_node(component={'name': 'custom_component', 'func': lambda x: x}, name='custom', inputs=['Query'])
pipeline.save_to_yaml('pipeline.yaml')  # This line triggers yaml.YAMLError
Fixed - works correctly
python
import os
from haystack import Pipeline

pipeline = Pipeline()
# Replace lambda with a serializable component or remove unsupported params
pipeline.add_node(component={'name': 'custom_component'}, name='custom', inputs=['Query'])

pipeline.save_to_yaml('pipeline.yaml')  # Fixed: no unserializable objects
print('Pipeline saved successfully')
Removed unserializable lambda function from component dict so YAML serialization succeeds without error.

Workaround

Catch yaml.YAMLError during pipeline save/load and serialize problematic components separately as JSON or strings, then reconstruct after loading.

Prevention

Design pipeline components and parameters to be YAML serializable from the start, using only primitives or custom serialization hooks; avoid manual YAML edits.

Python 3.9+ · haystack >=1.0.0 · tested on 1.14.0
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.