BoundaryML/baml · error · anyhow::Error
Error occurred while rendering prompt
Error message
Error occurred while rendering prompt: {minijinja_err} What it means
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).
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.
Example fix
// Fix the root cause shown in the chain, e.g.:
// before: {{ user | format }}
// after: {{ user | format(type='json') }} Defensive patterns
Strategy: try-catch
Try / catch
match render_prompt(...) {
Err(e) => {
// print full chain: {e:#} includes every 'caused by' level
eprintln!("prompt render failed: {e:#}");
// branch on the innermost cause to apply the targeted fix
}
Ok(p) => p,
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- BamlImage has no callable attribute
- CannotUnpack
- Encountered impossible jinja expression during parsing
- Expected a statically defined string, not expression
- Failed to get template
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/30040511744327fd.
Report an issue: GitHub.
Appendix: source
Thrown at engine/baml-lib/jinja-runtime/src/lib.rs:685
default_role,
allowed_roles,
remap_role,
enum_values_by_name,
});
match rendered {
Ok(r) => Ok(r),
Err(err) => {
let mut minijinja_err = "".to_string();
minijinja_err += &format!("{err:#}");
let mut err = &err as &dyn std::error::Error;
while let Some(next_err) = err.source() {
minijinja_err += &format!("\n\ncaused by: {next_err:#}");
err = next_err;
}
anyhow::bail!("Error occurred while rendering prompt: {minijinja_err}");
}
}
}
#[cfg(test)]
mod render_tests {
use std::sync::Once;
use baml_types::{BamlMap, BamlMediaType};
use indexmap::IndexMap;
use super::*;
static INIT: Once = Once::new();
pub fn setup_logging() {
INIT.call_once(|| {View on GitHub (pinned to bd85ce9dee)