deepset-ai/haystack · error · ValueError
Unknown component device type '{dict['type']}' in serialized
Error message
Unknown component device type '{dict['type']}' in serialized data What it means
ComponentDevice.from_dict() deserializes a dict produced by to_dict(), which must have type set to 'single' or 'multiple'. Any other 'type' value means the serialized data is corrupt, hand-written incorrectly, or produced by an incompatible version.
Source
Thrown at haystack/utils/device.py:484
return {"type": "multiple", "device_map": self._multiple_devices.to_dict()}
# Unreachable
raise AssertionError()
@classmethod
def from_dict(cls, dict: dict[str, Any]) -> "ComponentDevice": # noqa:A002
"""
Create a component device representation from a JSON-serialized dictionary.
:param dict:
The serialized representation.
:returns:
The deserialized component device.
"""
if dict["type"] == "single":
return cls.from_str(dict["device"])
if dict["type"] == "multiple":
return cls.from_multiple(DeviceMap.from_dict(dict["device_map"]))
raise ValueError(f"Unknown component device type '{dict['type']}' in serialized data")
def _get_default_device() -> Device:
"""
Return the default device for Haystack.
Precedence:
GPU > XPU > MPS > CPU. If PyTorch is not installed, only CPU is available.
:returns:
The default device.
"""
try:
torch_import.check()
has_mps = (
hasattr(torch.backends, "mps")
and torch.backends.mps.is_available()View on GitHub (pinned to e318778c9b)
Solutions
- Set 'type' to 'single' with a 'device' string key, or 'multiple' with a 'device_map' dict.
- Re-serialize the device/pipeline from a working ComponentDevice.to_dict() output.
- Check for version mismatch between the Haystack that saved the data and the one loading it.
Example fix
// before
ComponentDevice.from_dict({"type": "gpu", "device": "cuda:0"})
// after
ComponentDevice.from_dict({"type": "single", "device": "cuda:0"}) Defensive patterns
Strategy: validation
Validate before calling
def valid_device_dict(d):
return d.get("type") in ("single", "multiple") and ("device" in d or "device_map" in d) Type guard
def is_serialized_device(d: dict) -> bool:
return isinstance(d, dict) and d.get("type") in {"single", "multiple"} Try / catch
try:
dev = ComponentDevice.from_dict(d)
except ValueError:
dev = ComponentDevice.from_str(d.get("device", "cpu")) Prevention
- Only consume dicts produced by ComponentDevice.to_dict().
- Don't hand-edit serialized pipeline YAML device entries.
- Keep the Haystack version consistent between save and load.
When it happens
Trigger: Calling ComponentDevice.from_dict({'type': 'gpu', 'device': 'cuda:0'}) or loading YAML/JSON where the device entry's 'type' key was edited or came from an older schema.
Common situations: Hand-editing serialized pipeline YAML; deserializing pipelines saved by a different Haystack version; typos like 'Single' or 'multi'.
Related errors
- Refusing to deserialize an OutputAdapter with unsafe=True wh
- Refusing to deserialize an OutputAdapter with custom filters
- Couldn't deserialize component '{name}' of class '{component
- Component '{name}' of type '{type(component).__name__}' has
- Component '{name}' of type '{type(component).__name__}' has
AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30).
Data as JSON: /api/errors/d2ed39b2a899072e.
Report an issue: GitHub.