{"record":{"id":"3b315d6e6e4cc0cf","repo":"vllm-project/vllm","slug":"failed-to-render-jinja-template","errorCode":null,"errorMessage":"failed to render jinja template","messagePattern":"failed to render jinja template","errorType":"exception","errorClass":"TemplateError","httpStatus":null,"severity":"error","filePath":"rust/src/chat/src/renderer/hf/error.rs","lineNumber":8,"sourceCode":"// SPDX-License-Identifier: Apache-2.0\n// SPDX-FileCopyrightText: Copyright contributors to the vLLM project\n\nuse thiserror::Error as ThisError;\n\n#[derive(Debug, ThisError)]\npub(crate) enum TemplateError {\n    #[error(\"failed to render jinja template\")]\n    Jinja(#[from] minijinja::Error),\n    #[error(\"failed to read chat template file\")]\n    ReadTemplateFile(#[source] std::io::Error),\n    #[error(\"chat template looks like a file path but does not exist\")]\n    MissingTemplatePath,\n    #[error(\"failed to parse chat_template.json\")]\n    ParseTemplateJson(#[source] serde_json::Error),\n    #[error(\"chat_template.json does not contain a valid template\")]\n    InvalidTemplateJson,\n}\n","sourceCodeStart":1,"sourceCodeEnd":19,"githubUrl":"https://github.com/vllm-project/vllm/blob/c794754062d49a8fdb63ab3c5215b488b865030c/rust/src/chat/src/renderer/hf/error.rs#L1-L19","documentation":"HF chat renderer error: executing the model's Jinja chat template with minijinja failed; the minijinja error is attached via `#[from]`. This happens at prompt-rendering time, after the template was successfully loaded — the failure is in evaluating it against your messages.","triggerScenarios":"Rendering a chat request where the template references a variable/filter the renderer did not provide (e.g. `tools`, `documents`, custom filters like `strftime_now`), or message content of a type the template does not handle (array content against a template expecting a string).","commonSituations":"Templates from newer transformers versions using filters/features minijinja does not implement; sending `tools` to a template that never expected them; sending multimodal content blocks to a text-only template; tool messages with a template lacking tool-role support.","solutions":["Read the chained minijinja error — it names the undefined variable/filter and template line.","Remove or adapt the message type that triggers the failure (e.g. drop tools, convert array content to text).","Override the chat template with a compatible/simplified one via the renderer's template-override config.","Update the Rust chat crate if a newer version added support for the missing filter/feature."],"exampleFix":"// before\nmessages: vec![ChatMessage::user(Content::parts([...]))] // template does `message['content'].strip()`\n\n// after\nmessages: vec![ChatMessage::user(\"plain text\")] // or override template that handles parts","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match render_result {\n    Err(e) if e.to_string().contains(\"failed to render jinja template\") => {\n        // inspect e.source() chain: undefined variable/filter + template line\n        respond_bad_request(\"messages incompatible with this model's chat template\")\n    }\n    other => other?,\n}","preventionTips":["Smoke-test rendering with your exact message shapes (tools, multi-part content) at startup.","Pin a known-good chat template override instead of relying on model-repo template updates.","Read the chained minijinja error to find the exact undefined variable/filter."],"tags":["rust","jinja","chat-template","renderer","minijinja"],"backgroundTag":null,"analyzedSha":"c794754062d49a8fdb63ab3c5215b488b865030c","analyzedAt":"2026-08-14T21:17:39.825Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}