deepset-ai/haystack · error
Error dumping pipeline to YAML - Ensure that all pipeline co
Error message
Error dumping pipeline to YAML - Ensure that all pipeline components only serialize basic Python types
What it means
YamlMarshaller.marshal dumps a pipeline's dictionary to YAML, but YAML can only represent basic Python types. If any component's serialization output contains non-representable objects (custom classes, open file handles, etc.), yaml raises RepresenterError, which is re-raised as a TypeError with guidance to fix component serialization.
Source
Thrown at haystack/marshal/yaml.py:33
class YamlDumper(yaml.SafeDumper):
def represent_tuple(self, data: tuple) -> yaml.SequenceNode:
"""Represent a Python tuple."""
return self.represent_sequence("tag:yaml.org,2002:python/tuple", data)
YamlDumper.add_representer(tuple, YamlDumper.represent_tuple)
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
- Fix the offending component's to_dict to emit only basic types (str, int, float, bool, list, dict, None)
- Ensure to_dict only includes init_params plus serializable state, and to_dict/from_dict round-trip
- Temporarily use the JSON marshaller to locate the non-serializable value, then correct it
Example fix
// before
def to_dict(self):
return {"component": ..., "init_params": {"client": self.client}} # live object
// after
def to_dict(self):
return {"component": ..., "init_params": {"model": self.model_name}} # basic types only Defensive patterns
Strategy: try-catch
Validate before calling
def assert_basic_types(obj, path="root"):
if obj is None or isinstance(obj, (str, int, float, bool)):
return
if isinstance(obj, dict):
for k, v in obj.items(): assert_basic_types(v, f"{path}.{k}")
elif isinstance(obj, (list, tuple)):
for i, v in enumerate(obj): assert_basic_types(v, f"{path}[{i}]")
else:
raise TypeError(f"non-serializable {type(obj)!r} at {path}") Try / catch
try:
yaml_str = marshaller.marshal(pipeline_dict)
except TypeError as e:
if "dumping pipeline to YAML" in str(e):
# find and fix offending component's to_dict, then retry
yaml_str = marshaller.marshal(repaired_dict)
else:
raise Prevention
- Keep to_dict/to_dict outputs limited to basic Python types
- Round-trip test every custom component: dumps -> loads -> compare
- Never serialize live clients/objects; serialize their init params instead
When it happens
Trigger: Calling marshal (directly or via pipeline dumps) when a component's to_dict returns values like custom objects, sets of custom types, lambdas, or datetime-unfriendly objects that YamlDumper cannot represent.
Common situations: Custom components whose to_dict leaks runtime objects instead of init parameters; after upgrading a component that changed its serialized fields; third-party components not written for YAML round-tripping.
Related errors
- Error loading pipeline from YAML - Ensure that all pipeline
- Missing 'type' in component '{name}'
- Missing sender in connection: {connection}
- Missing receiver in connection: {connection}
- Error while unmarshalling serialized pipeline data. This is
AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30).
Data as JSON: /api/errors/4a7831251412a71f.
Report an issue: GitHub.