The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
fix(core): better error message for empty var names (#32073)
Isaac Francisco98bfd57a7623
diff --git a/libs/core/langchain_core/utils/mustache.py b/libs/core/langchain_core/utils/mustache.pyindex be0739568c..12cab8da0a 100644--- a/libs/core/langchain_core/utils/mustache.py+++ b/libs/core/langchain_core/utils/mustache.py@@ -150,6 +150,11 @@ def parse_tag(template: str, l_del: str, r_del: str) -> tuple[tuple[str, str], smsg = f"unclosed tag at line {_CURRENT_LINE}"raise ChevronError(msg) from e+ # Check for empty tags+ if not tag.strip():+ msg = f"empty tag at line {_CURRENT_LINE}"+ raise ChevronError(msg)+# Find the type meaning of the first charactertag_type = tag_types.get(tag[0], "variable")diff --git a/libs/core/tests/unit_tests/prompts/test_structured.py b/libs/core/tests/unit_tests/prompts/test_structured.pyindex 0b74b37cc6..fda2d00b36 100644--- a/libs/core/tests/unit_tests/prompts/test_structured.py+++ b/libs/core/tests/unit_tests/prompts/test_structured.py@@ -2,6 +2,7 @@ from functools import partialfrom inspect import isclassfrom typing import Any, Union, cast+import pytestfrom pydantic import BaseModelfrom langchain_core.language_models import FakeListChatModel@@ -10,6 +11,7 @@ from langchain_core.load.load import loadsfrom langchain_core.messages import HumanMessagefrom langchain_core.prompts.structured import StructuredPromptfrom langchain_core.runnables.base import Runnable, RunnableLambda+from langchain_core.utils.mustache import ChevronErrorfrom langchain_core.utils.pydantic import is_basemodel_subclass@@ -128,3 +130,8 @@ def test_structured_prompt_template_format() -> None:assert prompt.invoke({"person": {"name": "foo"}}).to_messages() == [HumanMessage("hi foo")]+++def test_structured_prompt_template_empty_vars() -> None:+ with pytest.raises(ChevronError, match="empty tag"):+ StructuredPrompt([("human", "hi {{}}")], schema={}, template_format="mustache")