test_mustache_prompt_from_template() — langchain Function Reference
Architecture documentation for the test_mustache_prompt_from_template() function in test_prompt.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 9f681d86_0f5b_1bf9_e8f8_5c33bf53ea1f["test_mustache_prompt_from_template()"] af1b998b_a7bf_9d5c_32ef_bab507a6bee3["test_prompt.py"] 9f681d86_0f5b_1bf9_e8f8_5c33bf53ea1f -->|defined in| af1b998b_a7bf_9d5c_32ef_bab507a6bee3 style 9f681d86_0f5b_1bf9_e8f8_5c33bf53ea1f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/tests/unit_tests/prompts/test_prompt.py lines 72–245
def test_mustache_prompt_from_template(snapshot: SnapshotAssertion) -> None:
"""Test prompts can be constructed from a template."""
# Single input variable.
template = "This is a {{foo}} test."
prompt = PromptTemplate.from_template(template, template_format="mustache")
assert prompt.format(foo="bar") == "This is a bar test."
assert prompt.input_variables == ["foo"]
assert prompt.get_input_jsonschema() == {
"title": "PromptInput",
"type": "object",
"properties": {"foo": {"title": "Foo", "type": "string", "default": None}},
}
# Multiple input variables.
template = "This {{bar}} is a {{foo}} test."
prompt = PromptTemplate.from_template(template, template_format="mustache")
assert prompt.format(bar="baz", foo="bar") == "This baz is a bar test."
assert prompt.input_variables == ["bar", "foo"]
assert prompt.get_input_jsonschema() == {
"title": "PromptInput",
"type": "object",
"properties": {
"bar": {"title": "Bar", "type": "string", "default": None},
"foo": {"title": "Foo", "type": "string", "default": None},
},
}
# Multiple input variables with repeats.
template = "This {{bar}} is a {{foo}} test {{&foo}}."
prompt = PromptTemplate.from_template(template, template_format="mustache")
assert prompt.format(bar="baz", foo="bar") == "This baz is a bar test bar."
assert prompt.input_variables == ["bar", "foo"]
assert prompt.get_input_jsonschema() == {
"title": "PromptInput",
"type": "object",
"properties": {
"bar": {"title": "Bar", "type": "string", "default": None},
"foo": {"title": "Foo", "type": "string", "default": None},
},
}
# Nested variables.
template = "This {{obj.bar}} is a {{obj.foo}} test {{{foo}}}."
prompt = PromptTemplate.from_template(template, template_format="mustache")
assert prompt.format(obj={"bar": "foo", "foo": "bar"}, foo="baz") == (
"This foo is a bar test baz."
)
assert prompt.input_variables == ["foo", "obj"]
if PYDANTIC_VERSION_AT_LEAST_29:
assert _normalize_schema(prompt.get_input_jsonschema()) == snapshot(
name="schema_0"
)
# . variables
template = "This {{.}} is a test."
prompt = PromptTemplate.from_template(template, template_format="mustache")
assert prompt.format(foo="baz") == ("This {'foo': 'baz'} is a test.")
assert prompt.input_variables == []
assert prompt.get_input_jsonschema() == {
"title": "PromptInput",
"type": "object",
"properties": {},
}
# section/context variables
template = """This{{#foo}}
{{bar}}
{{/foo}}is a test."""
prompt = PromptTemplate.from_template(template, template_format="mustache")
assert prompt.format(foo={"bar": "yo"}) == (
"""This
yo
is a test."""
)
assert prompt.input_variables == ["foo"]
if PYDANTIC_VERSION_AT_LEAST_29:
assert _normalize_schema(prompt.get_input_jsonschema()) == snapshot(
name="schema_2"
)
# more complex nested section/context variables
Domain
Subdomains
Source
Frequently Asked Questions
What does test_mustache_prompt_from_template() do?
test_mustache_prompt_from_template() is a function in the langchain codebase, defined in libs/core/tests/unit_tests/prompts/test_prompt.py.
Where is test_mustache_prompt_from_template() defined?
test_mustache_prompt_from_template() is defined in libs/core/tests/unit_tests/prompts/test_prompt.py at line 72.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free