{"record":{"id":"f77f24ad9e2b20a7","repo":"deepset-ai/haystack","slug":"component-name-of-type-type-component-nam-f77f24","errorCode":null,"errorMessage":"Component '{name}' of type '{type(component).__name__}' has a non-string key in the serialized data.","messagePattern":"Component '(.+?)' of type '(.+?)' has a non-string key in the serialized data\\.","errorType":"exception","errorClass":"SerializationError","httpStatus":null,"severity":"error","filePath":"haystack/core/serialization.py","lineNumber":111,"sourceCode":"    # Ensure that only basic Python types are used in the serde data.\n    def is_allowed_type(obj: Any) -> bool:\n        return isinstance(obj, (str, int, float, bool, list, dict, set, tuple, type(None)))\n\n    def check_iterable(iterable: Iterable[Any]) -> None:\n        for v in iterable:\n            if not is_allowed_type(v):\n                raise SerializationError(\n                    f\"Component '{name}' of type '{type(component).__name__}' has an unsupported value \"\n                    f\"of type '{type(v).__name__}' in the serialized data.\"\n                )\n            if isinstance(v, (list, set, tuple)):\n                check_iterable(v)\n            elif isinstance(v, dict):\n                check_dict(v)\n\n    def check_dict(d: dict[str, Any]) -> None:\n        if any(not isinstance(k, str) for k in d):\n            raise SerializationError(\n                f\"Component '{name}' of type '{type(component).__name__}' has a non-string key in the serialized data.\"\n            )\n\n        for k, v in d.items():\n            if not is_allowed_type(v):\n                raise SerializationError(\n                    f\"Component '{name}' of type '{type(component).__name__}' has an unsupported value \"\n                    f\"of type '{type(v).__name__}' in the serialized data under key '{k}'.\"\n                )\n            if isinstance(v, (list, set, tuple)):\n                check_iterable(v)\n            elif isinstance(v, dict):\n                check_dict(v)\n\n    check_dict(data)\n\n\ndef generate_qualified_class_name(cls: type[object]) -> str:","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/core/serialization.py#L93-L129","documentation":"Serialized component data must have string keys in every dict (JSON requirement). Haystack raises this during validation of a component's to_dict() output when any dict at any level has a non-string key (e.g. int, enum, tuple). This prevents data loss when the dict is written to JSON/YAML.","triggerScenarios":"Calling pipeline.dumps() when a component's serialized init_parameters contain a dict keyed by ints or enum members, e.g. {1: \"a\"} or {MyEnum.X: 1}.","commonSituations":"Components that use enums or integer IDs as dict keys; passing a raw dict with non-str keys as an init parameter; mapping objects built from {int: str} lookups.","solutions":["Fix the component's to_dict() to convert keys to strings (e.g. str(key)).","Update from_dict() to convert keys back to their original type on deserialization.","Change the init parameter so keys are strings at construction time.","Use enum .name or .value as the key instead of the enum object."],"exampleFix":"// before\n{\"init_parameters\": {\"rates\": {1: 0.5, 2: 0.3}}}\n\n// after\n{\"init_parameters\": {\"rates\": {\"1\": 0.5, \"2\": 0.3}}}  # from_dict converts keys back to int","handlingStrategy":"validation","validationCode":"def check_keys(obj) -> list:\n    bad = []\n    if isinstance(obj, dict):\n        bad += [k for k in obj if not isinstance(k, str)]\n        for v in obj.values(): bad += check_keys(v)\n    elif isinstance(obj, (list, tuple, set)):\n        for v in obj: bad += check_keys(v)\n    return bad","typeGuard":"def str_keys_only(d) -> bool:\n    return isinstance(d, dict) and all(isinstance(k, str) for k in d)","tryCatchPattern":"from haystack.core.errors import SerializationError\ntry:\n    pipeline.dumps()\nexcept SerializationError as e:\n    if \"non-string key\" in str(e): ...\nraise","preventionTips":[],"tags":["serialization","python","haystack"],"backgroundTag":"non-string-dict-key","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}