diff --git a/libs/core/langchain_core/prompts/prompt.py b/libs/core/langchain_core/prompts/prompt.py index 8c9732b2daf..36ed47250ce 100644 --- a/libs/core/langchain_core/prompts/prompt.py +++ b/libs/core/langchain_core/prompts/prompt.py @@ -138,8 +138,8 @@ class PromptTemplate(StringPromptTemplate): # Allow for easy combining if isinstance(other, PromptTemplate): if self.template_format != other.template_format: - msg = "Cannot add two templates of different formats" - raise ValueError(msg) + msg = "Cannot add templates of different formats" + raise ValueError(msg) input_variables = list( set(self.input_variables) | set(other.input_variables) ) @@ -160,7 +160,10 @@ class PromptTemplate(StringPromptTemplate): validate_template=validate_template, ) if isinstance(other, str): - prompt = PromptTemplate.from_template(other, template_format=self.template_format) + prompt = PromptTemplate.from_template( + other, + template_format=self.template_format, + ) return self + prompt msg = f"Unsupported operand type for +: {type(other)}" raise NotImplementedError(msg) diff --git a/libs/core/tests/unit_tests/prompts/test_prompt.py b/libs/core/tests/unit_tests/prompts/test_prompt.py index 12315e1a264..3d09882fd69 100644 --- a/libs/core/tests/unit_tests/prompts/test_prompt.py +++ b/libs/core/tests/unit_tests/prompts/test_prompt.py @@ -684,7 +684,7 @@ def test_prompt_with_template_variable_name_jinja2() -> None: def test_prompt_template_add_with_with_another_format(): - with pytest.raises(match=r"Cannot add two templates"): + with pytest.raises(match=r"Cannot add templates"): PromptTemplate.from_template("This is a {template}") + PromptTemplate.from_template("So {{this}} is", template_format="mustache")