{"record":{"id":"6c57b41930f96487","repo":"deepset-ai/haystack","slug":"chat-generators-must-be-a-non-empty-list","errorCode":null,"errorMessage":"'chat_generators' must be a non-empty list","messagePattern":"'chat_generators' must be a non-empty list","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"haystack/components/generators/chat/fallback.py","lineNumber":60,"sourceCode":"\n    Fail over is automatically triggered when a generator raises any exception, including:\n    - Timeout errors (if the generator implements and raises them)\n    - Rate limit errors (429)\n    - Authentication errors (401)\n    - Context length errors (400)\n    - Server errors (500+)\n    - Any other exception\n    \"\"\"\n\n    def __init__(self, chat_generators: list[ChatGenerator]) -> None:\n        \"\"\"\n        Creates an instance of FallbackChatGenerator.\n\n        :param chat_generators: A non-empty list of chat generator components to try in order.\n        \"\"\"\n        if not chat_generators:\n            msg = \"'chat_generators' must be a non-empty list\"\n            raise ValueError(msg)\n\n        self.chat_generators = list(chat_generators)\n\n    def to_dict(self) -> dict[str, Any]:\n        \"\"\"Serialize the component, including nested chat generators.\"\"\"\n        return default_to_dict(\n            self,\n            chat_generators=[\n                component_to_dict(gen, name=f\"chat_generator_{idx}\") for idx, gen in enumerate(self.chat_generators)\n            ],\n        )\n\n    @classmethod\n    def from_dict(cls, data: dict[str, Any]) -> FallbackChatGenerator:\n        \"\"\"Rebuild the component from a serialized representation, restoring nested chat generators.\"\"\"\n        # Reconstruct nested chat generators from their serialized dicts\n        init_params = data.get(\"init_parameters\", {})\n        serialized = init_params.get(\"chat_generators\") or []","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/generators/chat/fallback.py#L42-L78","documentation":"FallbackChatGenerator wraps a list of chat generators to try in order, so it requires at least one. An empty (or falsy) `chat_generators` list makes the component useless, and __init__ raises ValueError immediately rather than failing later at run time.","triggerScenarios":"Calling `FallbackChatGenerator([])` or `FallbackChatGenerator()` with no generators, or with an empty list produced by an expression (e.g. [g for g in gen_list] that matched nothing).","commonSituations":"Building the generator list dynamically from configuration where no candidates matched; YAML pipelines with an empty list literal; filtering out generators by model availability and ending up with none.","solutions":["Pass at least one chat generator, e.g. FallbackChatGenerator([OpenAIChatGenerator()])","Validate the candidate list is non-empty before constructing the component","Guard the construction site: skip creating the fallback if the list is empty or raise a clearer domain error"],"exampleFix":"// before\ngen = FallbackChatGenerator([])\n// after\nif not candidates:\n    raise ValueError(\"no chat generators configured\")\ngen = FallbackChatGenerator(candidates)","handlingStrategy":"validation","validationCode":"if not chat_generators:\n    raise ValueError(\"chat_generators must contain at least one generator\")\ngenerator = FallbackChatGenerator(chat_generators)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass list literals built by filtering without a non-empty assert","Add config-schema validation that rejects empty generator lists","Document a required default generator in pipeline templates"],"tags":["validation","fallback","configuration","empty-list"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}