The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
fix(core): fix nested mustache variable extraction and update docs (#34872)
Nandana Dileepef067078b89a
diff --git a/libs/core/langchain_core/prompts/string.py b/libs/core/langchain_core/prompts/string.pyindex e0eb642306..a7e1263544 100644--- a/libs/core/langchain_core/prompts/string.py+++ b/libs/core/langchain_core/prompts/string.py@@ -258,7 +258,7 @@ def get_template_variables(template: str, template_format: str) -> list[str]:template: The template string.template_format: The template format.- Should be one of `'f-string'` or `'jinja2'`.+ Should be one of `'f-string'`, `'mustache'` or `'jinja2'`.Returns:The variables from the template.diff --git a/libs/core/tests/unit_tests/prompts/test_string.py b/libs/core/tests/unit_tests/prompts/test_string.pyindex 96c573c72f..c338a12822 100644--- a/libs/core/tests/unit_tests/prompts/test_string.py+++ b/libs/core/tests/unit_tests/prompts/test_string.py@@ -1,7 +1,7 @@import pytestfrom packaging import version-from langchain_core.prompts.string import mustache_schema+from langchain_core.prompts.string import get_template_variables, mustache_schemafrom langchain_core.utils.pydantic import PYDANTIC_VERSIONPYDANTIC_VERSION_AT_LEAST_29 = version.parse("2.9") <= PYDANTIC_VERSION@@ -30,3 +30,12 @@ def test_mustache_schema_parent_child() -> None:}actual = mustache_schema(template).model_json_schema()assert expected == actual+++def test_get_template_variables_mustache_nested() -> None:+ template = "Hello {{user.name}}, your role is {{user.role}}"+ template_format = "mustache"+ # Returns only the top-level key for mustache templates+ expected = ["user"]+ actual = get_template_variables(template, template_format)+ assert actual == expected