{"record":{"id":"d24022216b3f6f2e","repo":"BoundaryML/baml","slug":"jinja-expressions-cannot-be-resolved-without-a-template","errorCode":null,"errorMessage":"Jinja expressions cannot be resolved without a template context","messagePattern":"Jinja expressions cannot be resolved without a template context","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-types/src/value_expr.rs","lineNumber":305,"sourceCode":"    pub fn maybe_eq(&self, other: &StringOr) -> bool {\n        match (self, other) {\n            (Self::Value(s), Self::Value(o)) => s == o,\n            (Self::Value(_), _) | (_, Self::Value(_)) => true,\n            (Self::EnvVar(_), Self::JinjaExpression(_))\n            | (Self::JinjaExpression(_), Self::EnvVar(_)) => true,\n            (Self::JinjaExpression(_), Self::JinjaExpression(_)) => true,\n            (Self::EnvVar(s), Self::EnvVar(o)) => s == o,\n            // Template string calls could evaluate to anything, so conservatively return true\n            (Self::TemplateStringCall { .. }, _) | (_, Self::TemplateStringCall { .. }) => true,\n        }\n    }\n\n    pub fn resolve(&self, ctx: &impl GetEnvVar) -> Result<String> {\n        match self {\n            Self::EnvVar(name) => ctx.get_env_var(name),\n            Self::Value(value) => Ok(value.to_string()),\n            Self::JinjaExpression(_) => {\n                anyhow::bail!(\"Jinja expressions cannot be resolved without a template context\")\n            }\n            Self::TemplateStringCall { name, .. } => {\n                anyhow::bail!(\n                    \"Template string call '{}' cannot be resolved without IR context. \\\n                     Use resolve_with_templates() instead.\",\n                    name\n                )\n            }\n        }\n    }\n\n    /// Resolve this StringOr, with support for template_string calls.\n    pub fn resolve_with_templates(\n        &self,\n        ctx: &impl GetEnvVar,\n        template_renderer: &impl TemplateStringRenderer,\n    ) -> Result<String> {\n        match self {","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-types/src/value_expr.rs#L287-L323","documentation":"ValueExpr::resolve handles only statically-known variants: EnvVar and Value. JinjaExpression needs a rendered template context to evaluate, so resolve explicitly rejects it with this error instead of silently producing a wrong string. The variant is not an error per se — the wrong resolution API was used.","triggerScenarios":"Calling resolve() on a ValueExpr that contains Self::JinjaExpression, e.g. resolving API key expressions or config values that embed {{ ... }} Jinja expressions without a template context.","commonSituations":"Resolving client/API-key configuration strings that users wrote with Jinja expressions (e.g. dynamic headers) via the simple env-var-only resolver.","solutions":["Use resolve_with_templates() (or the full IR-aware resolver) which supplies a template context.","Ensure a template renderer is available where the ValueExpr is resolved.","If the value should be static, replace the Jinja expression in the configuration with a literal or env-var reference."],"exampleFix":"// before\nlet v = expr.resolve(&env)?;\n// after\nlet v = expr.resolve_with_templates(&env, &template_renderer)?;","handlingStrategy":"type-guard","validationCode":"if matches!(expr, ValueExpr::JinjaExpression(_) | ValueExpr::TemplateStringCall { .. }) { return Err(anyhow!(\"needs template-aware resolver\")); }","typeGuard":"fn is_statically_resolvable(e: &ValueExpr) -> bool { matches!(e, ValueExpr::EnvVar(_) | ValueExpr::Value(_)) }","tryCatchPattern":"let v = expr.resolve_with_templates(&env, &renderer).map_err(|e| anyhow!(\"resolution failed: {}\", e))?;","preventionTips":["Use resolve_with_templates when configs may contain Jinja","Validate ValueExpr variants before choosing a resolver","Keep a template renderer available wherever config resolution happens"],"tags":["rust","jinja","resolution"],"backgroundTag":"missing-template-context","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}