{"record":{"id":"30040511744327fd","repo":"BoundaryML/baml","slug":"error-occurred-while-rendering-prompt-minijinja-err","errorCode":null,"errorMessage":"Error occurred while rendering prompt: {minijinja_err}","messagePattern":"Error occurred while rendering prompt: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-lib/jinja-runtime/src/lib.rs","lineNumber":685,"sourceCode":"        default_role,\n        allowed_roles,\n        remap_role,\n        enum_values_by_name,\n    });\n\n    match rendered {\n        Ok(r) => Ok(r),\n        Err(err) => {\n            let mut minijinja_err = \"\".to_string();\n            minijinja_err += &format!(\"{err:#}\");\n\n            let mut err = &err as &dyn std::error::Error;\n            while let Some(next_err) = err.source() {\n                minijinja_err += &format!(\"\\n\\ncaused by: {next_err:#}\");\n                err = next_err;\n            }\n\n            anyhow::bail!(\"Error occurred while rendering prompt: {minijinja_err}\");\n        }\n    }\n}\n\n#[cfg(test)]\nmod render_tests {\n\n    use std::sync::Once;\n\n    use baml_types::{BamlMap, BamlMediaType};\n    use indexmap::IndexMap;\n\n    use super::*;\n\n    static INIT: Once = Once::new();\n\n    pub fn setup_logging() {\n        INIT.call_once(|| {","sourceCodeStart":667,"sourceCodeEnd":703,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/jinja-runtime/src/lib.rs#L667-L703","documentation":"When minijinja rendering fails inside render_prompt, BAML walks the error's source chain, appends each level as 'caused by: ...', and re-raises everything under this single anyhow error. It is a wrapper: the real diagnosis is in the chained causes (which include errors 810–818 above).","triggerScenarios":"Any template rendering failure — missing variables, bad filters, role() misuse, unparseable media markers — surfaces as this wrapper error with the underlying minijinja error and its causes embedded in the message.","commonSituations":"Prompt templates referencing undefined variables; syntax errors in .baml templates; filter misuse (format/role errors above); debugging CI failures where only the top-level message is logged.","solutions":["Read the full message including every 'caused by:' segment — the root cause is at the end of the chain.","Fix the underlying template issue identified in the innermost cause (undefined variable, bad filter arg, etc.).","Test the template with a minimal render call to isolate which expression fails.","If the cause is unclear, render a stripped-down version of the template to bisect the failing expression."],"exampleFix":"// Fix the root cause shown in the chain, e.g.:\n// before: {{ user | format }}\n// after:  {{ user | format(type='json') }}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"match render_prompt(...) {\n    Err(e) => {\n        // print full chain: {e:#} includes every 'caused by' level\n        eprintln!(\"prompt render failed: {e:#}\");\n        // branch on the innermost cause to apply the targeted fix\n    }\n    Ok(p) => p,\n}","preventionTips":["Always log renderer errors with the full source chain ({e:#} / {err.stack}), not just the top message.","Validate all template variables exist before rendering.","Bisect failing templates by rendering minimal snippets.","Add CI checks that render every .baml prompt with sample args."],"tags":["jinja","template-rendering","error-wrapper","rust"],"backgroundTag":"template-render-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}