{"record":{"id":"d74eb1127d5a1f77","repo":"deepset-ai/haystack","slug":"missing-type-in-key-serialization-data","errorCode":null,"errorMessage":"Missing 'type' in {key} serialization data","messagePattern":"Missing 'type' in (.+?) serialization data","errorType":"exception","errorClass":"DeserializationError","httpStatus":null,"severity":"error","filePath":"haystack/utils/deserialization.py","lineNumber":49,"sourceCode":"    :param data:\n        The dictionary with the serialized data.\n    :param key:\n        The key in the dictionary where the Component is stored. Default is \"chat_generator\".\n\n    :raises DeserializationError:\n        If the key is missing in the serialized data, the value is not a dictionary,\n        the type key is missing, the class cannot be imported, or the class lacks a 'from_dict' method.\n    \"\"\"\n    if key not in data:\n        raise DeserializationError(f\"Missing '{key}' in serialization data\")\n\n    serialized_component = data[key]\n\n    if not isinstance(serialized_component, dict):\n        raise DeserializationError(f\"The value of '{key}' is not a dictionary\")\n\n    if \"type\" not in serialized_component:\n        raise DeserializationError(f\"Missing 'type' in {key} serialization data\")\n\n    try:\n        component_class = import_class_by_name(serialized_component[\"type\"])\n    except ImportError as e:\n        raise DeserializationError(f\"Class '{serialized_component['type']}' not correctly imported\") from e\n\n    data[key] = component_from_dict(cls=component_class, data=serialized_component, name=key)\n","sourceCodeStart":31,"sourceCodeEnd":57,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/utils/deserialization.py#L31-L57","documentation":"Raised by deserialize_component_inplace when the serialized dict for `key` exists and is a dict, but lacks the required 'type' field identifying which Haystack component class to instantiate. Haystack pipeline/component deserialization relies on 'type' (fully-qualified class path) to locate the class and call its from_dict.","triggerScenarios":"Calling Pipeline.loads()/from_dict or deserialize_component_inplace/deserialize_chatgenerator_inplace on YAML/JSON where a component entry (e.g. under 'components') has no 'type' key — typically hand-edited serialization data or data produced by an older Haystack version with a different serialization format.","commonSituations":"Hand-editing exported pipeline YAML and deleting the type line; migrating pipelines serialized by Haystack 1.x into Haystack 2.x; programmatically building a serialized dict and forgetting the 'type' field.","solutions":["Add a 'type' key with the fully-qualified class path, e.g. haystack.components.generators.OpenAIGenerator, to the component's serialization dict","Re-serialize the pipeline/component from a working instance using Pipeline.dumps()/to_dict() instead of hand-writing the data","Verify the data format matches the current Haystack version; migrate old 1.x YAML to 2.x format"],"exampleFix":"// before\ndata = {\"chat_generator\": {\"init_parameters\": {\"model\": \"gpt-4o\"}}}\n// after\ndata = {\"chat_generator\": {\"type\": \"haystack.components.generators.chat.OpenAIChatGenerator\", \"init_parameters\": {\"model\": \"gpt-4o\"}}}","handlingStrategy":"validation","validationCode":"def has_component_type(data: dict, key: str = \"chat_generator\") -> bool:\n    comp = data.get(key)\n    return isinstance(comp, dict) and \"type\" in comp\n# call before deserialization: assert has_component_type(data)","typeGuard":"def is_serialized_component(v: object) -> bool:\n    return isinstance(v, dict) and isinstance(v.get(\"type\"), str)","tryCatchPattern":"from haystack.core.errors import DeserializationError\ntry:\n    deserialize_component_inplace(data, key=\"chat_generator\")\nexcept DeserializationError as e:\n    # recover: re-serialize or fix the dict\n    raise ValueError(f\"Invalid serialized component: {e}\") from e","preventionTips":["Always produce serialization data via to_dict()/dumps(), never hand-written dicts","Validate pipeline YAML contains a 'type' key per component before loading","Keep 'type' values as full dotted class paths"],"tags":["deserialization","yaml","pipeline","missing-field"],"backgroundTag":"missing-required-serialization-field","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}