{"record":{"id":"5f7c8dcd49bd99ab","repo":"deepset-ai/haystack","slug":"could-not-apply-arguments-generic-args-to-type","errorCode":null,"errorMessage":"Could not apply arguments {generic_args} to type {main_type}","messagePattern":"Could not apply arguments (.+?) to type (.+?)","errorType":"exception","errorClass":"DeserializationError","httpStatus":null,"severity":"error","filePath":"haystack/utils/type_serialization.py","lineNumber":261,"sourceCode":"    if \"[\" in type_str and type_str.endswith(\"]\"):\n        main_type_str, generics_str = type_str.split(\"[\", 1)\n        generics_str = generics_str[:-1]\n\n        main_type = deserialize_type(main_type_str)\n\n        # Parse literal args with ast.literal_eval, which safely handles\n        # str/int/bool/None/bytes and is quote-aware, so a comma inside a string value does not split the\n        # arguments.\n        if main_type is typing.Literal:\n            return typing.Literal[ast.literal_eval(f\"({generics_str},)\")]\n\n        generic_args = [_deserialize_type_arg(arg) for arg in _parse_generic_args(generics_str)]\n\n        # Reconstruct\n        try:\n            return main_type[tuple(generic_args) if len(generic_args) > 1 else generic_args[0]]\n        except (TypeError, AttributeError) as e:\n            raise DeserializationError(f\"Could not apply arguments {generic_args} to type {main_type}\") from e\n\n    # Handle non-generic types\n    # First, check if there's a module prefix\n    if \".\" in type_str:\n        try:\n            return _import_class_by_name(type_str)\n        except ImportError as e:\n            raise DeserializationError(str(e)) from e\n\n    # No module prefix, check builtins and typing.\n    # (None / NoneType / Ellipsis are handled at the top of this function, before they can reach the\n    # builtin type gate below which would refuse them for not being types.)\n    if hasattr(builtins, type_str):\n        resolved = getattr(builtins, type_str)\n        # This bare-name path never consults the allowlist. A type annotation must resolve to an\n        # actual type, so builtin functions like `eval`/`exec` are rejected while types pass.\n        _check_builtin_is_type(resolved, type_str)\n        return resolved","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/utils/type_serialization.py#L243-L279","documentation":"deserialize_type() reconstructs generic types like list[int] by parsing the serialized generic arguments and subscripting the resolved main type. When main_type[...] raises TypeError or AttributeError (e.g. the base type is not subscriptable or does not accept those args), haystack wraps it in DeserializationError with this message. It signals the serialized type string is structurally incompatible with the resolved type.","triggerScenarios":"Calling deserialize_type() (directly or via from_dict/_schema_from_dict) on a string whose main type cannot take the parsed generic args, e.g. 'int[str]', 'dict[int]' with wrong arity, or a custom class that doesn't support __class_getitem__.","commonSituations":"Loading pipeline/component YAML written for a different haystack version where the type changed generic arity; hand-edited serialization dicts; a custom class renamed or replaced by a non-generic type after serialization.","solutions":["Check the serialized type string: verify the main type actually supports the generic arguments (arity and kinds)","Fix or regenerate the serialized dict/pipeline YAML so the type matches the current code version","If it's your own class, implement __class_getitem__ or make it subscriptable, or serialize it without generics","Import the resolved main type in a REPL and test main_type[args] manually to see the underlying TypeError"],"exampleFix":"// before\ndeserialize_type(\"int[str]\")  # DeserializationError\n// after\ndeserialize_type(\"list[int]\")  # or make the class generic-capable","handlingStrategy":"try-catch","validationCode":"import builtins, typing\ndef check_generic(type_str):\n    main = type_str.split(\"[\")[0]\n    return \".\" in main or hasattr(builtins, main) or hasattr(typing, main)","typeGuard":"def is_subscriptable(t):\n    return hasattr(t, \"__class_getitem__\")","tryCatchPattern":"from haystack.utils import DeserializationError\ntry:\n    t = deserialize_type(type_str)\nexcept DeserializationError as e:\n    log.error(\"bad serialized type: %s\", e)\n    t = fallback_type","preventionTips":["Keep serialized pipeline dicts/YAML in sync with the library version that produced them","Only serialize types that are subscriptable and accept the given generic arity","Add a smoke test that deserializes all stored pipeline definitions"],"tags":["python","deserialization","generics","haystack"],"backgroundTag":"type-deserialization-failed","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}