parse_tag() — langchain Function Reference
Architecture documentation for the parse_tag() function in mustache.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 0fd46fbf_924b_0a2e_ebc6_df49a6d4a2de["parse_tag()"] 88ae0419_8f6b_8b31_dd8f_a3bc6bbcb7b6["mustache.py"] 0fd46fbf_924b_0a2e_ebc6_df49a6d4a2de -->|defined in| 88ae0419_8f6b_8b31_dd8f_a3bc6bbcb7b6 ee317545_08fa_c1b5_d4bc_6d8f5e1e4e7c["tokenize()"] ee317545_08fa_c1b5_d4bc_6d8f5e1e4e7c -->|calls| 0fd46fbf_924b_0a2e_ebc6_df49a6d4a2de style 0fd46fbf_924b_0a2e_ebc6_df49a6d4a2de fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/core/langchain_core/utils/mustache.py lines 118–191
def parse_tag(template: str, l_del: str, r_del: str) -> tuple[tuple[str, str], str]:
"""Parse a tag from a template.
Args:
template: The template.
l_del: The left delimiter.
r_del: The right delimiter.
Returns:
The tag and the template.
Raises:
ChevronError: If the tag is unclosed.
ChevronError: If the set delimiter tag is unclosed.
"""
tag_types = {
"!": "comment",
"#": "section",
"^": "inverted section",
"/": "end",
">": "partial",
"=": "set delimiter?",
"{": "no escape?",
"&": "no escape",
}
# Get the tag
try:
tag, template = template.split(r_del, 1)
except ValueError as e:
msg = 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 character
tag_type = tag_types.get(tag[0], "variable")
# If the type is not a variable
if tag_type != "variable":
# Then that first character is not needed
tag = tag[1:]
# If we might be a set delimiter tag
if tag_type == "set delimiter?":
# Double check to make sure we are
if tag.endswith("="):
tag_type = "set delimiter"
# Remove the equal sign
tag = tag[:-1]
# Otherwise we should complain
else:
msg = f"unclosed set delimiter tag\nat line {_CURRENT_LINE}"
raise ChevronError(msg)
elif (
# If we might be a no html escape tag
tag_type == "no escape?"
# And we have a third curly brace
# (And are using curly braces as delimiters)
and l_del == "{{"
and r_del == "}}"
and template.startswith("}")
):
# Then we are a no html escape tag
template = template[1:]
tag_type = "no escape"
# Strip the whitespace off the key and return
return ((tag_type, tag.strip()), template)
Domain
Subdomains
Defined In
Called By
Source
Frequently Asked Questions
What does parse_tag() do?
parse_tag() is a function in the langchain codebase, defined in libs/core/langchain_core/utils/mustache.py.
Where is parse_tag() defined?
parse_tag() is defined in libs/core/langchain_core/utils/mustache.py at line 118.
What calls parse_tag()?
parse_tag() is called by 1 function(s): tokenize.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free