langchain-ai/langchain · error · ValueError

Unsupported template format: {template_format}

Error message

Unsupported template format: {template_format}

What it means

Raised by `get_template_variables` in `langchain_core.prompts.string` when `template_format` is not one of the three branches it handles explicitly: 'jinja2', 'f-string', or 'mustache'. Unlike `check_valid_template` (which maps through a formatter dict and includes the accepted list in its message), this dispatcher simply raises `ValueError: Unsupported template format: ...` in its `else` branch.

Source

Thrown at libs/core/langchain_core/prompts/string.py:323

            Should be one of `'f-string'`, `'mustache'` or `'jinja2'`.

    Returns:
        The variables from the template.

    Raises:
        ValueError: If the template format is not supported.
    """
    input_variables: list[str] | set[str]
    if template_format == "jinja2":
        # Get the variables for the template
        input_variables = sorted(_get_jinja2_variables_from_template(template))
    elif template_format == "f-string":
        input_variables = validate_f_string_template(template)
    elif template_format == "mustache":
        input_variables = mustache_template_vars(template)
    else:
        msg = f"Unsupported template format: {template_format}"
        raise ValueError(msg)

    return sorted(input_variables)


class StringPromptTemplate(BasePromptTemplate[str], ABC):
    """String prompt that exposes the format method, returning a prompt."""

    @classmethod
    def get_lc_namespace(cls) -> list[str]:
        """Get the namespace of the LangChain object.

        Returns:
            `["langchain", "prompts", "base"]`
        """
        return ["langchain", "prompts", "base"]

    def format_prompt(self, **kwargs: Any) -> PromptValue:
        """Format the prompt with the inputs.

View on GitHub (pinned to e32fa9a52e)

Solutions

  1. Pass exactly 'f-string', 'jinja2', or 'mustache'
  2. Normalize and whitelist the value before calling: `assert fmt in {"f-string", "jinja2", "mustache"}`
  3. If the value comes from config, strip and lowercase it once at load time and fail fast with a clear config error

Example fix

# before
fmt = config["format"]              # "F-String"
get_template_variables(t, fmt)      # ValueError: Unsupported template format: F-String

# after
fmt = config["format"].strip().lower()
assert fmt in {"f-string", "jinja2", "mustache"}, f"bad format in config: {fmt!r}"
get_template_variables(t, fmt)
Defensive patterns

Strategy: validation

Validate before calling

SUPPORTED = {"f-string", "jinja2", "mustache"}

def checked_format(fmt: str) -> str:
    if fmt not in SUPPORTED:
        msg = f"unsupported template format {fmt!r}; expected one of {sorted(SUPPORTED)}"
        raise ValueError(msg)
    return fmt

vars_ = get_template_variables(t, checked_format(fmt))

Type guard

def is_supported_format(fmt: str) -> bool:
    return fmt in {"f-string", "jinja2", "mustache"}

Prevention

When it happens

Trigger: Calling `get_template_variables(template, "f-string ")` (trailing space), `"F-string"`, or any unknown string such as `"template"`. Also reachable indirectly when prompt code passes a user-supplied format string straight through.

Common situations: Format strings sourced from YAML/JSON config or CLI flags without normalization; version skew where a format name valid elsewhere is not recognized here; whitespace or casing introduced by config parsing.

Related errors


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