{"record":{"id":"3aa4b2835bbdef72","repo":"BoundaryML/baml","slug":"failed-to-get-template","errorCode":null,"errorMessage":"Failed to get template '{}': {}","messagePattern":"Failed to get template '(.+?)': (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-core/src/ir/ir_helpers/mod.rs","lineNumber":2086,"sourceCode":"                    \"{{% macro {name}({args}) %}}{template}{{% endmacro %}}\",\n                    name = t.name(),\n                    args = args_str,\n                    template = t.template(),\n                )\n            })\n            .chain(std::iter::once(template_content.to_string()))\n            .collect::<Vec<_>>()\n            .join(\"\\n\");\n\n        // Use the shared environment (trim_blocks, lstrip_blocks, debug,\n        // null formatter, regex_match/sum filters) to match the prompt renderer.\n        let mut env = get_env();\n        env.add_template(\"__template__\", &full_template)\n            .map_err(|e| anyhow::anyhow!(\"Failed to parse template '{}': {}\", name, e))?;\n\n        let tmpl = env\n            .get_template(\"__template__\")\n            .map_err(|e| anyhow::anyhow!(\"Failed to get template '{}': {}\", name, e))?;\n\n        let context = minijinja::Value::from_serialize(&args_map);\n        let rendered = tmpl\n            .render(context)\n            .map_err(|e| anyhow::anyhow!(\"Failed to render template '{}': {}\", name, e))?;\n\n        Ok(rendered)\n    }\n}\n\n#[cfg(test)]\nmod render_template_tests {\n    use baml_types::TemplateStringRenderer;\n    use repr::make_test_ir;\n\n    use super::*;\n\n    #[test]","sourceCodeStart":2068,"sourceCodeEnd":2104,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-core/src/ir/ir_helpers/mod.rs#L2068-L2104","documentation":"BAML renders Jinja-templated prompt parts with minijinja. After adding the template to the render environment, it fetches it back by name; if the get fails, BAML wraps the minijinja error in this message. This indicates the template engine refused to return a template that was just registered, typically due to template-name or environment issues.","triggerScenarios":"Calling BAML's template rendering helper (render_template in ir_helpers) when minijinja's env.get_template(\"__template__\") fails after env.add_template succeeded — e.g. internal environment state inconsistency or engine-level rejection of the template.","commonSituations":"BAML internal/template engine version mismatch; corrupted or non-UTF8 prompt template content; concurrency issues with the shared Jinja environment. Rarely caused directly by user code since the template name is the fixed internal name \"__template__\".","solutions":["Check your BAML version and upgrade to the latest — this is often fixed in newer minijinja/baml-core releases.","Inspect the inner minijinja error (printed after ': {}' in the message) for the real cause.","Simplify the prompt template (remove exotic Jinja syntax, ensure valid UTF-8) and retry.","If reproducible, file an issue with the BAML team — this path is normally unreachable for valid templates."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match render_template(&name, &args) {\n    Ok(rendered) => rendered,\n    Err(e) if e.to_string().contains(\"Failed to get template\") => {\n        // log inner minijinja cause, retry with upgraded baml, or fail fast\n        eprintln!(\"template env error: {e:#}\");\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Keep BAML and its template engine dependencies up to date.","Keep prompt templates in simple, valid UTF-8 Jinja syntax.","Report persistent occurrences upstream with a minimal repro."],"tags":["jinja","template","baml","rust"],"backgroundTag":"resource-not-found","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}