{"record":{"id":"5e50437031b775a1","repo":"vllm-project/vllm","slug":"chat-template-json-does-not-contain-a-valid-templa","errorCode":null,"errorMessage":"chat_template.json does not contain a valid template","messagePattern":"chat_template\\.json does not contain a valid template","errorType":"exception","errorClass":"TemplateError","httpStatus":null,"severity":"error","filePath":"rust/src/chat/src/renderer/hf/error.rs","lineNumber":16,"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":"`chat_template.json` parsed as JSON but did not contain a valid template where one is required (`template.rs:72` fails `serde_json::from_value` into the expected shape and maps the failure to this variant). The file's structure is wrong — e.g. missing the expected template field or holding an unexpected type.","triggerScenarios":"A chat_template.json that is valid JSON but, at the point a specific template is requested, the corresponding entry is absent or not a string/map the renderer can use — e.g. requesting the tool template when the JSON only defines a base chat_template.","commonSituations":"Model repos whose chat_template.json layout differs from the transformers version the renderer targets; hand-rolled chat_template.json with only custom templates; requesting a named template variant that the model author never shipped.","solutions":["Inspect chat_template.json and confirm it contains the template kind being requested (base chat template and any named variants).","Fall back to an inline template override or a template file instead of chat_template.json.","If a specific named variant is missing, use the model's default template rather than requesting the variant."],"exampleFix":"// before\n{\"tool_use_template\": \"...\"} // renderer needs base \"chat_template\" entry\n\n// after\n{\"chat_template\": \"...\", \"tool_use_template\": \"...\"}","handlingStrategy":"validation","validationCode":"let json: serde_json::Value = serde_json::from_str(&raw)?;\nif json.get(\"chat_template\").or_else(|| json.get(\"default\")).is_none() {\n    return Err(\"chat_template.json has no usable template entry\");\n}","typeGuard":null,"tryCatchPattern":"match result {\n    Err(TemplateError::InvalidTemplateJson) => {\n        eprintln!(\"chat_template.json lacks the required template entry; override with an explicit template\");\n        std::process::exit(2);\n    }\n    other => other?,\n}","preventionTips":["Only request template variants you have confirmed exist in the model's chat_template.json.","Keep an explicit template override ready for models with nonstandard template files."],"tags":["rust","chat-template","json","validation","transformers"],"backgroundTag":null,"analyzedSha":"c794754062d49a8fdb63ab3c5215b488b865030c","analyzedAt":"2026-08-14T21:17:39.825Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}