{"record":{"id":"e80bc92d895c0303","repo":"deepset-ai/haystack","slug":"required-variables-must-not-be-empty-set-it-to","errorCode":null,"errorMessage":"required_variables must not be empty. Set it to '*' to require all variables, or provide a non-empty list of variable names.","messagePattern":"required_variables must not be empty\\. Set it to '\\*' to require all variables, or provide a non-empty list of variable names\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"haystack/components/generators/chat/llm.py","lineNumber":83,"sourceCode":"            Only relevant when `user_prompt` or `system_prompt` contains template variables.\n        :param streaming_callback: A callback that will be invoked when a response is streamed from the LLM.\n        :raises ValueError: If user_prompt contains template variables but required_variables is an empty list.\n        \"\"\"\n        super(LLM, self).__init__(  # noqa: UP008\n            chat_generator=chat_generator,\n            system_prompt=system_prompt,\n            user_prompt=user_prompt,\n            required_variables=required_variables,\n            streaming_callback=streaming_callback,\n        )\n        if self._user_chat_prompt_builder is None or len(self._user_chat_prompt_builder.variables) == 0:\n            # This means user_prompt is empty or has no template variables.\n            # To ensure properly scheduling we then require messages to be passed at runtime.\n            component.set_input_type(self, \"messages\", list[ChatMessage])\n        else:\n            # user prompt was provided with variables\n            if isinstance(required_variables, list) and len(required_variables) == 0:\n                raise ValueError(\n                    \"required_variables must not be empty. Set it to '*' to require all variables, \"\n                    \"or provide a non-empty list of variable names.\"\n                )\n            component.set_input_type(self, \"messages\", list[ChatMessage], None)\n\n        # The Agent base class declares `step_count` and `tool_call_counts` as outputs, but an LLM never has tools\n        # and always runs exactly one step — those values are uninformative, so drop them from the public surface.\n        # `token_usage` is still meaningful and stays exposed.\n        component.set_output_types(\n            self, messages=list[ChatMessage], last_message=ChatMessage, token_usage=dict[str, Any]\n        )\n\n    def to_dict(self) -> dict[str, Any]:\n        \"\"\"\n        Serialize the LLM component to a dictionary.\n\n        :return: Dictionary with serialized data.\n        \"\"\"","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/generators/chat/llm.py#L65-L101","documentation":"PromptBuilder-style LLM component (llm.py) validates `required_variables` at init: an explicit empty list is ambiguous (require nothing? everything?), so it's rejected. Pass '*' to require all template variables or a non-empty list of variable names.","triggerScenarios":"`_LLMComponent(..., required_variables=[])` — typically when building the list dynamically and it ends up empty; also triggered when wiring the component for Agent pipelines with an empty list literal.","commonSituations":"Computing required_variables from user input or config that yielded no items; defaulting to `[]` instead of None/'*'; refactors where variables were removed but the parameter kept as [].","solutions":["Pass required_variables='*' to require all template variables","Pass a non-empty list like required_variables=['question']","If nothing is required, omit the parameter (default None) instead of passing []","Fix the upstream expression producing the empty list"],"exampleFix":"// before\nllm = _LLMComponent(generator, required_variables=[])\n// after\nllm = _LLMComponent(generator, required_variables=\"*\")","handlingStrategy":"validation","validationCode":"if isinstance(required_variables, list) and len(required_variables) == 0:\n    required_variables = \"*\"  # or omit the argument entirely","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use '*' or a non-empty list; omit the parameter when nothing is required","When building the list dynamically, validate it before wiring the component","Prefer computing required_variables from the template's variables automatically"],"tags":["validation","template-variables","configuration"],"backgroundTag":"invalid-constructor-argument","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}