{"record":{"id":"d2a0264082ffa009","repo":"deepset-ai/haystack","slug":"the-self-class-name-requires-a-non-empty","errorCode":null,"errorMessage":"The {self.__class__.__name__} requires a non-empty list of ChatMessage instances. Please provide a valid list of ChatMessage instances to render the prompt.","messagePattern":"The (.+?) requires a non-empty list of ChatMessage instances\\. Please provide a valid list of ChatMessage instances to render the prompt\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/components/builders/chat_prompt_builder.py","lineNumber":247,"sourceCode":"        :param template_variables:\n            An optional dictionary of template variables to overwrite the pipeline variables.\n        :param kwargs:\n            Pipeline variables used for rendering the prompt.\n\n        :returns: A dictionary with the following keys:\n            - `prompt`: The updated list of `ChatMessage` objects after rendering the templates.\n        :raises ValueError:\n            If `chat_messages` is empty or contains elements that are not instances of `ChatMessage`.\n        \"\"\"\n        kwargs = kwargs or {}\n        template_variables = template_variables or {}\n        template_variables_combined = {**kwargs, **template_variables}\n\n        if template is None:\n            template = self.template\n\n        if not template:\n            raise ValueError(\n                f\"The {self.__class__.__name__} requires a non-empty list of ChatMessage instances. \"\n                f\"Please provide a valid list of ChatMessage instances to render the prompt.\"\n            )\n\n        if isinstance(template, list) and not all(isinstance(message, ChatMessage) for message in template):\n            raise ValueError(\n                f\"The {self.__class__.__name__} expects a list containing only ChatMessage instances. \"\n                f\"The provided list contains other types. Please ensure that all elements in the list \"\n                f\"are ChatMessage instances.\"\n            )\n\n        processed_messages = []\n        if isinstance(template, list):\n            for message in template:\n                if message.is_from(ChatRole.USER) or message.is_from(ChatRole.SYSTEM):\n                    self._validate_variables(set(template_variables_combined.keys()))\n                    if message.text is None:\n                        raise ValueError(NO_TEXT_ERROR_MESSAGE.format(role=message.role.value, message=message))","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/components/builders/chat_prompt_builder.py#L229-L265","documentation":"ChatPromptBuilder.run (via _render_prompt_messages) raises when the effective template is falsy — i.e. neither run's template argument nor self.template contains a non-empty list of ChatMessages. Without a template there is nothing to render, so the call is invalid.","triggerScenarios":"Calling run() without a template argument on a builder constructed with template=None (e.g. created with template=None and required_variables, expecting template at run time) or passing template=[].","commonSituations":"Wiring ChatPromptBuilder in a pipeline with dynamic templates but forgetting to connect the template input; instantiating with template=None and never passing it in run; passing an empty list after filtering messages.","solutions":["Pass a non-empty list of ChatMessage objects to run(template=[...]).","Provide the template at construction: ChatPromptBuilder(template=[...]).","Check that a pipeline connection feeding the template input is actually bound and non-empty."],"exampleFix":"// before\nbuilder = ChatPromptBuilder(template=None, required_variables=['q'])\nresult = builder.run()  # no template anywhere\n// after\nresult = builder.run(template=[ChatMessage.from_user('Question: {{ q }}')], q=q)","handlingStrategy":"validation","validationCode":"if not template:\n    raise ValueError('template must be a non-empty list of ChatMessage before calling run')","typeGuard":"def is_valid_template(t) -> bool:\n    return bool(t) and isinstance(t, list)","tryCatchPattern":"try:\n    res = builder.run(template=template, **kwargs)\nexcept ValueError as e:\n    if 'requires a non-empty list' in str(e):\n        template = default_template\n        res = builder.run(template=template, **kwargs)\n    else:\n        raise","preventionTips":["Pass the template at construction when it is static.","Verify pipeline connections bound to the template input.","Guard dynamic template sources against empty lists."],"tags":["validation","chat-prompt-builder","empty-input"],"backgroundTag":"missing-required-input","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}