deepset-ai/haystack · error
'chat_generators' must be a non-empty list
Error message
'chat_generators' must be a non-empty list
What it means
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.
Source
Thrown at haystack/components/generators/chat/fallback.py:60
Fail over is automatically triggered when a generator raises any exception, including:
- Timeout errors (if the generator implements and raises them)
- Rate limit errors (429)
- Authentication errors (401)
- Context length errors (400)
- Server errors (500+)
- Any other exception
"""
def __init__(self, chat_generators: list[ChatGenerator]) -> None:
"""
Creates an instance of FallbackChatGenerator.
:param chat_generators: A non-empty list of chat generator components to try in order.
"""
if not chat_generators:
msg = "'chat_generators' must be a non-empty list"
raise ValueError(msg)
self.chat_generators = list(chat_generators)
def to_dict(self) -> dict[str, Any]:
"""Serialize the component, including nested chat generators."""
return default_to_dict(
self,
chat_generators=[
component_to_dict(gen, name=f"chat_generator_{idx}") for idx, gen in enumerate(self.chat_generators)
],
)
@classmethod
def from_dict(cls, data: dict[str, Any]) -> FallbackChatGenerator:
"""Rebuild the component from a serialized representation, restoring nested chat generators."""
# Reconstruct nested chat generators from their serialized dicts
init_params = data.get("init_parameters", {})
serialized = init_params.get("chat_generators") or []View on GitHub (pinned to e318778c9b)
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
Example fix
// before
gen = FallbackChatGenerator([])
// after
if not candidates:
raise ValueError("no chat generators configured")
gen = FallbackChatGenerator(candidates) Defensive patterns
Strategy: validation
Validate before calling
if not chat_generators:
raise ValueError("chat_generators must contain at least one generator")
generator = FallbackChatGenerator(chat_generators) Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Hook of type '{type(h).__name__}' is registered under hook p
- 'dimension' must be a positive integer.
- 'dimension' must be a positive integer.
- required_variables must not be empty. Set it to '*' to requi
- 'responses' must not be an empty list.
AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30).
Data as JSON: /api/errors/6c57b41930f96487.
Report an issue: GitHub.