langchain-ai/langchain · error · ChevronError

empty tag at line

Error message

empty tag at line {_CURRENT_LINE}

What it means

Raised by the Mustache tokenizer in `langchain_core.utils.mustache` when a tag parses successfully (both delimiters found) but its body is empty or whitespace-only, e.g. `{{ }}` or `{{}}`. An empty tag has no variable name to look up, so it is rejected as malformed. The line number in the message is where the tag appears.

Solutions

  1. Find the empty tag on the reported line and either give it a name (`{{name}}`) or delete it.
  2. If the tag was produced by string substitution, guard that the substituted name is non-empty before building the template.
  3. Validate templates by tokenizing once at load time so malformed tags fail fast during development.

Example fix

# before
template = "Hello {{ }}!"
MustachePlaceholderFormatter().format(template)  # ChevronError: empty tag

# after
template = "Hello {{name}}!"
MustachePlaceholderFormatter().format(template, name="Ada")
Defensive patterns

Strategy: validation

Validate before calling

import re

def has_empty_tags(template: str) -> bool:
    return bool(re.search(r"\{\{\s*\}\}", template))

if has_empty_tags(template):
    raise ValueError("template contains an empty tag")

Try / catch

try:
    list(tokenize(template))
except ChevronError as e:
    raise ValueError(f"invalid template: {e}") from e

Prevention

When it happens

Trigger: Formatting a template with `MustachePlaceholderFormatter` that contains `{{}}`, `{{ }}`, or a tag whose name was removed by an editing mistake; frequently a leftover after deleting a variable name but leaving the braces.

Common situations: Editing prompt templates and deleting the variable name but not the braces; templating pipelines that substitute variable names with empty strings before rendering (`{{%s}} % var` with empty `var`); copy-pasted templates with placeholder braces meant to be filled in later.

Related errors


AI-assisted analysis of langchain-ai/langchain@e32fa9a52e (2026-08-14). Data as JSON: /api/errors/794552bdc41dd0b6. Report an issue: GitHub.

Appendix: source

Thrown at libs/core/langchain_core/utils/mustache.py:154

        "^": "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

View on GitHub (pinned to e32fa9a52e)