{"record":{"id":"be435f700b7267d6","repo":"deepset-ai/haystack","slug":"stateschema-key-param-is-missing-a-type-ent","errorCode":null,"errorMessage":"StateSchema: Key '{param}' is missing a 'type' entry.","messagePattern":"StateSchema: Key '(.+?)' is missing a 'type' entry\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/components/agents/state/state.py","lineNumber":69,"sourceCode":"        if config.get(\"handler\"):\n            deserialized_schema[param][\"handler\"] = deserialize_callable(config[\"handler\"])\n\n    return deserialized_schema\n\n\ndef _validate_schema(schema: dict[str, Any]) -> None:\n    \"\"\"\n    Validate that a schema dictionary meets all required constraints.\n\n    Checks that each parameter definition has a valid type field and that any handler\n    specified is a callable function.\n\n    :param schema: Dictionary mapping parameter names to their type and handler configs\n    :raises ValueError: If schema validation fails due to missing or invalid fields\n    \"\"\"\n    for param, definition in schema.items():\n        if \"type\" not in definition:\n            raise ValueError(f\"StateSchema: Key '{param}' is missing a 'type' entry.\")\n        if not _is_valid_type(definition[\"type\"]):\n            raise ValueError(f\"StateSchema: 'type' for key '{param}' must be a Python type, got {definition['type']}\")\n        if definition.get(\"handler\") is not None and not callable(definition[\"handler\"]):\n            raise ValueError(f\"StateSchema: 'handler' for key '{param}' must be callable or None\")\n        if param == \"messages\":  # definition[\"type\"] != list[ChatMessage] but split to cover also List[ChatMessage]\n            if not _is_list_type(definition[\"type\"]):\n                raise ValueError(f\"StateSchema: 'messages' must be of type list[ChatMessage], got {definition['type']}\")\n            # Check if the list contains ChatMessage elements\n            args = get_args(definition[\"type\"])\n            if not args or not issubclass(args[0], ChatMessage):\n                raise ValueError(f\"StateSchema: 'messages' must be of type list[ChatMessage], got {definition['type']}\")\n\n\nclass State:\n    \"\"\"\n    State is a container for storing shared information during the execution of an Agent and its tools.\n\n    For instance, State can be used to store documents, context, and intermediate results.","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/agents/state/state.py#L51-L87","documentation":"StateSchema validation raises this ValueError when a schema entry dict lacks the required 'type' key. Every parameter in a state schema must declare its Python type so the state container can validate and merge values.","triggerScenarios":"Constructing StateSchema (directly or via Agent state_schema) with an entry like {\"param\": {\"handler\": my_handler}} that omits 'type'.","commonSituations":"Hand-written schema dicts where a key was given only a handler, typos like 'types' instead of 'type', or programmatically built schemas missing a branch.","solutions":["Add a 'type' entry with a Python type to each schema key, e.g. {\"param\": {\"type\": list}}","Check for typos: the key must be exactly 'type'","If using serialized schemas, validate them with _validate_schema or a unit test before use"],"exampleFix":"// before\nschema = {\"numbers\": {\"handler\": merge_numbers}}\n// after\nschema = {\"numbers\": {\"type\": list, \"handler\": merge_numbers}}","handlingStrategy":"validation","validationCode":"def schema_has_types(schema):\n    return all(isinstance(d, dict) and \"type\" in d for d in schema.values())","typeGuard":"def is_valid_schema_entry(entry) -> bool:\n    return isinstance(entry, dict) and \"type\" in entry and isinstance(entry[\"type\"], type)","tryCatchPattern":"try:\n    schema = StateSchema(my_schema)\nexcept ValueError as e:\n    if \"missing a 'type' entry\" in str(e):\n        key = str(e).split(\"'\")[1]\n        my_schema[key][\"type\"] = default_types[key]\n    else:\n        raise","preventionTips":["Always pair every schema key with a 'type' entry","Write a unit test that constructs your schema","Watch for typos like 'types' or 'Type'"],"tags":["python","schema-validation","agent","state"],"backgroundTag":"schema-validation-failed","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}