deepset-ai/haystack · error · SerializationError
Cannot determine the value of the init parameter '{param_nam
Error message
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. What it means
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.
Source
Thrown at haystack/core/serialization.py:76
If the values of the init parameters can't be determined.
If a non-basic Python type is used in the serialized data.
"""
if hasattr(obj, "to_dict"):
data = obj.to_dict()
else:
init_parameters = {}
for param_name, param in inspect.signature(obj.__init__).parameters.items():
# Ignore `args` and `kwargs`, used by the default constructor
if param_name in ("args", "kwargs"):
continue
try:
# This only works if the Component constructor assigns the init
# parameter to an instance variable or property with the same name
param_value = getattr(obj, param_name)
except AttributeError as e:
# If the parameter doesn't have a default value, raise an error
if param.default is param.empty:
raise SerializationError(
f"Cannot determine the value of the init parameter '{param_name}' "
f"for the class {obj.__class__.__name__}."
f"You can fix this error by assigning 'self.{param_name} = {param_name}' or adding a "
f"custom serialization method 'to_dict' to the class."
) from e
# In case the init parameter was not assigned, we use the default value
param_value = param.default
init_parameters[param_name] = param_value
data = default_to_dict(obj, **init_parameters)
_validate_component_to_dict_output(obj, name, data)
return data
def _validate_component_to_dict_output(component: Any, name: str, data: dict[str, Any]) -> None:
# Ensure that only basic Python types are used in the serde data.
def is_allowed_type(obj: Any) -> bool:View on GitHub (pinned to e318778c9b)
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.
Example fix
// before
class MyComponent:
def __init__(self, threshold: float):
self.cutoff = threshold # name mismatch; required param 'threshold' not stored
// after
class MyComponent:
def __init__(self, threshold: float):
self.threshold = threshold
Defensive patterns
Strategy: validation
Validate before calling
import inspect
for name, p in inspect.signature(MyComponent.__init__).parameters.items():
if name == 'self' or p.default is not inspect.Parameter.empty:
continue
if not hasattr(instance, name):
raise TypeError(f'store self.{name} = {name} in __init__ or implement to_dict') Type guard
def serializable_init_params(cls, instance) -> bool:
import inspect
sig = inspect.signature(cls.__init__)
return all(
p.default is not inspect.Parameter.empty or hasattr(instance, n)
for n, p in sig.parameters.items() if n not in ('self', 'args', 'kwargs')
) Try / catch
try:
d = component.to_dict()
except SerializationError as e:
print(e) # names the class and param; fix __init__ or add to_dict Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- {type(self.chat_generator).__name__} does not accept tools p
- Pre-init hooks do not support components with variadic posit
- Output type specifications of 'run' and 'run_async' methods
- set_input_types()/set_input_type() cannot override the param
- Parameters of 'run' and 'run_async' methods must be the same
AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30).
Data as JSON: /api/errors/14ebcb45b3889d23.
Report an issue: GitHub.