diff --git a/haystack/components/builders/prompt_builder.py b/haystack/components/builders/prompt_builder.py index 5cd4821c8..d8495d01b 100644 --- a/haystack/components/builders/prompt_builder.py +++ b/haystack/components/builders/prompt_builder.py @@ -1,9 +1,8 @@ -from typing import Dict, Any +from typing import Any, Dict from jinja2 import Template, meta -from haystack import component -from haystack import default_to_dict +from haystack import component, default_to_dict @component @@ -31,7 +30,8 @@ class PromptBuilder: self.template = Template(template) ast = self.template.environment.parse(template) template_variables = meta.find_undeclared_variables(ast) - component.set_input_types(self, **{var: Any for var in template_variables}) + for var in template_variables: + component.set_input_type(self, var, Any, "") def to_dict(self) -> Dict[str, Any]: return default_to_dict(self, template=self._template_string) diff --git a/releasenotes/notes/prompt-builder-default-value-95383dd6d17a05d5.yaml b/releasenotes/notes/prompt-builder-default-value-95383dd6d17a05d5.yaml new file mode 100644 index 000000000..b6f70c746 --- /dev/null +++ b/releasenotes/notes/prompt-builder-default-value-95383dd6d17a05d5.yaml @@ -0,0 +1,5 @@ +--- +fixes: + - | + Fix `PromptBuilder` missing input default values. + These missing default value was causing the PromptBuilder to never run if certain inputs are not received.