{"record":{"id":"4a7831251412a71f","repo":"deepset-ai/haystack","slug":"error-dumping-pipeline-to-yaml-ensure-that-all-p","errorCode":null,"errorMessage":"Error dumping pipeline to YAML - Ensure that all pipeline components only serialize basic Python types","messagePattern":"Error dumping pipeline to YAML - Ensure that all pipeline components only serialize basic Python types","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"haystack/marshal/yaml.py","lineNumber":33,"sourceCode":"\n\nclass YamlDumper(yaml.SafeDumper):\n    def represent_tuple(self, data: tuple) -> yaml.SequenceNode:\n        \"\"\"Represent a Python tuple.\"\"\"\n        return self.represent_sequence(\"tag:yaml.org,2002:python/tuple\", data)\n\n\nYamlDumper.add_representer(tuple, YamlDumper.represent_tuple)\nYamlLoader.add_constructor(\"tag:yaml.org,2002:python/tuple\", YamlLoader.construct_python_tuple)\n\n\nclass YamlMarshaller:\n    def marshal(self, dict_: dict[str, Any]) -> str:\n        \"\"\"Return a YAML representation of the given dictionary.\"\"\"\n        try:\n            return yaml.dump(dict_, Dumper=YamlDumper)\n        except yaml.representer.RepresenterError as e:\n            raise TypeError(\n                \"Error dumping pipeline to YAML - Ensure that all pipeline components only serialize basic Python types\"\n            ) from e\n\n    def unmarshal(self, data_: str | bytes | bytearray) -> dict[str, Any]:\n        \"\"\"Return a dictionary from the given YAML data.\"\"\"\n        try:\n            return yaml.load(data_, Loader=YamlLoader)\n        except yaml.constructor.ConstructorError as e:\n            raise TypeError(\n                \"Error loading pipeline from YAML - Ensure that all pipeline \"\n                \"components only serialize basic Python types\"\n            ) from e\n","sourceCodeStart":15,"sourceCodeEnd":46,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/marshal/yaml.py#L15-L46","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\ndef to_dict(self):\n    return {\"component\": ..., \"init_params\": {\"client\": self.client}}  # live object\n// after\ndef to_dict(self):\n    return {\"component\": ..., \"init_params\": {\"model\": self.model_name}}  # basic types only","handlingStrategy":"try-catch","validationCode":"def assert_basic_types(obj, path=\"root\"):\n    if obj is None or isinstance(obj, (str, int, float, bool)):\n        return\n    if isinstance(obj, dict):\n        for k, v in obj.items(): assert_basic_types(v, f\"{path}.{k}\")\n    elif isinstance(obj, (list, tuple)):\n        for i, v in enumerate(obj): assert_basic_types(v, f\"{path}[{i}]\")\n    else:\n        raise TypeError(f\"non-serializable {type(obj)!r} at {path}\")","typeGuard":null,"tryCatchPattern":"try:\n    yaml_str = marshaller.marshal(pipeline_dict)\nexcept TypeError as e:\n    if \"dumping pipeline to YAML\" in str(e):\n        # find and fix offending component's to_dict, then retry\n        yaml_str = marshaller.marshal(repaired_dict)\n    else:\n        raise","preventionTips":["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"],"tags":["python","yaml","serialization","pipeline"],"backgroundTag":"yaml-serialization-failed","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}