{"record":{"id":"c82a6c460663778c","repo":"langchain-ai/langchain","slug":"unsupported-template-format-template-format","errorCode":null,"errorMessage":"Unsupported template format: {template_format}","messagePattern":"Unsupported template format: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/core/langchain_core/prompts/string.py","lineNumber":323,"sourceCode":"            Should be one of `'f-string'`, `'mustache'` or `'jinja2'`.\n\n    Returns:\n        The variables from the template.\n\n    Raises:\n        ValueError: If the template format is not supported.\n    \"\"\"\n    input_variables: list[str] | set[str]\n    if template_format == \"jinja2\":\n        # Get the variables for the template\n        input_variables = sorted(_get_jinja2_variables_from_template(template))\n    elif template_format == \"f-string\":\n        input_variables = validate_f_string_template(template)\n    elif template_format == \"mustache\":\n        input_variables = mustache_template_vars(template)\n    else:\n        msg = f\"Unsupported template format: {template_format}\"\n        raise ValueError(msg)\n\n    return sorted(input_variables)\n\n\nclass StringPromptTemplate(BasePromptTemplate[str], ABC):\n    \"\"\"String prompt that exposes the format method, returning a prompt.\"\"\"\n\n    @classmethod\n    def get_lc_namespace(cls) -> list[str]:\n        \"\"\"Get the namespace of the LangChain object.\n\n        Returns:\n            `[\"langchain\", \"prompts\", \"base\"]`\n        \"\"\"\n        return [\"langchain\", \"prompts\", \"base\"]\n\n    def format_prompt(self, **kwargs: Any) -> PromptValue:\n        \"\"\"Format the prompt with the inputs.","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/langchain-ai/langchain/blob/e32fa9a52eab3b61ad7a45399bfde59b3e580fc4/libs/core/langchain_core/prompts/string.py#L305-L341","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Pass exactly 'f-string', 'jinja2', or 'mustache'","Normalize and whitelist the value before calling: `assert fmt in {\"f-string\", \"jinja2\", \"mustache\"}`","If the value comes from config, strip and lowercase it once at load time and fail fast with a clear config error"],"exampleFix":"# before\nfmt = config[\"format\"]              # \"F-String\"\nget_template_variables(t, fmt)      # ValueError: Unsupported template format: F-String\n\n# after\nfmt = config[\"format\"].strip().lower()\nassert fmt in {\"f-string\", \"jinja2\", \"mustache\"}, f\"bad format in config: {fmt!r}\"\nget_template_variables(t, fmt)","handlingStrategy":"validation","validationCode":"SUPPORTED = {\"f-string\", \"jinja2\", \"mustache\"}\n\ndef checked_format(fmt: str) -> str:\n    if fmt not in SUPPORTED:\n        msg = f\"unsupported template format {fmt!r}; expected one of {sorted(SUPPORTED)}\"\n        raise ValueError(msg)\n    return fmt\n\nvars_ = get_template_variables(t, checked_format(fmt))","typeGuard":"def is_supported_format(fmt: str) -> bool:\n    return fmt in {\"f-string\", \"jinja2\", \"mustache\"}","tryCatchPattern":null,"preventionTips":["Normalize format strings (strip/lower) once where config enters the program","Keep a single source-of-truth constant for supported formats","Add schema validation for config files that carry template_format"],"tags":["prompts","template-format","valueerror","validation"],"backgroundTag":null,"analyzedSha":"e32fa9a52eab3b61ad7a45399bfde59b3e580fc4","analyzedAt":"2026-08-14T18:42:09.092Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}