{"record":{"id":"14ebcb45b3889d23","repo":"deepset-ai/haystack","slug":"cannot-determine-the-value-of-the-init-parameter","errorCode":null,"errorMessage":"Cannot determine the value of the init parameter '{param_name}' for the class {obj.__class__.__name__}.You can fix this error by assigning 'self.{param_name} = {param_name}' or adding a custom serialization method 'to_dict' to the class.","messagePattern":"Cannot determine the value of the init parameter '(.+?)' for the class (.+?)\\.You can fix this error by assigning 'self\\.(.+?) = (.+?)' or adding a custom serialization method 'to_dict' to the class\\.","errorType":"exception","errorClass":"SerializationError","httpStatus":null,"severity":"error","filePath":"haystack/core/serialization.py","lineNumber":76,"sourceCode":"        If the values of the init parameters can't be determined.\n        If a non-basic Python type is used in the serialized data.\n    \"\"\"\n    if hasattr(obj, \"to_dict\"):\n        data = obj.to_dict()\n    else:\n        init_parameters = {}\n        for param_name, param in inspect.signature(obj.__init__).parameters.items():\n            # Ignore `args` and `kwargs`, used by the default constructor\n            if param_name in (\"args\", \"kwargs\"):\n                continue\n            try:\n                # This only works if the Component constructor assigns the init\n                # parameter to an instance variable or property with the same name\n                param_value = getattr(obj, param_name)\n            except AttributeError as e:\n                # If the parameter doesn't have a default value, raise an error\n                if param.default is param.empty:\n                    raise SerializationError(\n                        f\"Cannot determine the value of the init parameter '{param_name}' \"\n                        f\"for the class {obj.__class__.__name__}.\"\n                        f\"You can fix this error by assigning 'self.{param_name} = {param_name}' or adding a \"\n                        f\"custom serialization method 'to_dict' to the class.\"\n                    ) from e\n                # In case the init parameter was not assigned, we use the default value\n                param_value = param.default\n            init_parameters[param_name] = param_value\n\n        data = default_to_dict(obj, **init_parameters)\n\n    _validate_component_to_dict_output(obj, name, data)\n    return data\n\n\ndef _validate_component_to_dict_output(component: Any, name: str, data: dict[str, Any]) -> None:\n    # Ensure that only basic Python types are used in the serde data.\n    def is_allowed_type(obj: Any) -> bool:","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/core/serialization.py#L58-L94","documentation":"component_to_dict (serialization.py:76) raises SerializationError when it cannot determine the value of a required __init__ parameter for a component being serialized. It infers init parameter values from same-named instance attributes; if the attribute is missing and the parameter has no default, serialization cannot proceed. The error tells you exactly how to fix it.","triggerScenarios":"A component whose __init__ takes a required parameter but never stores it as self.<param_name>; calling component.to_dict() or pipeline dumps (to_dict/to_yaml) on such a component; pytest haystack test helpers like test_to_dict.","commonSituations":"Custom components storing params under different attribute names or computed into other state; components refactored so init params are only used transiently; vendored/third-party components lacking to_dict.","solutions":["Assign the init parameter to an attribute of the same name in __init__: self.<param_name> = <param_name>.","Implement a custom to_dict() (and from_dict()) on the component that serializes the parameter explicitly.","Give the init parameter a default value so serialization can fall back to it.","If you don't own the component, subclass it and add to_dict."],"exampleFix":"// before\nclass MyComponent:\n    def __init__(self, threshold: float):\n        self.cutoff = threshold  # name mismatch; required param 'threshold' not stored\n// after\nclass MyComponent:\n    def __init__(self, threshold: float):\n        self.threshold = threshold\n","handlingStrategy":"validation","validationCode":"import inspect\nfor name, p in inspect.signature(MyComponent.__init__).parameters.items():\n    if name == 'self' or p.default is not inspect.Parameter.empty:\n        continue\n    if not hasattr(instance, name):\n        raise TypeError(f'store self.{name} = {name} in __init__ or implement to_dict')","typeGuard":"def serializable_init_params(cls, instance) -> bool:\n    import inspect\n    sig = inspect.signature(cls.__init__)\n    return all(\n        p.default is not inspect.Parameter.empty or hasattr(instance, n)\n        for n, p in sig.parameters.items() if n not in ('self', 'args', 'kwargs')\n    )","tryCatchPattern":"try:\n    d = component.to_dict()\nexcept SerializationError as e:\n    print(e)  # names the class and param; fix __init__ or add to_dict","preventionTips":["Always assign every required init parameter to self.<same_name> in component __init__.","Implement to_dict/from_dict for components with derived or renamed state.","Run haystack's pytest helpers (test_to_dict) on custom components in CI.","Give init parameters sensible defaults where possible."],"tags":["serialization","component","to-dict"],"backgroundTag":"serialization-init-param-unresolvable","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}