{"record":{"id":"55f1d9f0a0cf8fb4","repo":"BoundaryML/baml","slug":"template-string-call-cannot-be-resolved-without-ir-context","errorCode":null,"errorMessage":"Template string call '{}' cannot be resolved without IR context. Use resolve_with_templates() instead.","messagePattern":"Template string call '(.+?)' cannot be resolved without IR context\\. Use resolve_with_templates\\(\\) instead\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-types/src/value_expr.rs","lineNumber":308,"sourceCode":"            (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 {\n            Self::EnvVar(name) => ctx.get_env_var(name),\n            Self::Value(value) => Ok(value.to_string()),\n            Self::JinjaExpression(_) => {","sourceCodeStart":290,"sourceCodeEnd":326,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-types/src/value_expr.rs#L290-L326","documentation":"ValueExpr::resolve cannot evaluate TemplateStringCall variants: template string calls require the intermediate representation (IR) to know the function being called. resolve deliberately fails with a pointer to the correct API, resolve_with_templates(). It is a guard against resolving IR-dependent expressions without IR context.","triggerScenarios":"Calling resolve() on a ValueExpr::TemplateStringCall, i.e. a config/prompt value that invokes a BAML template-string function, using only an env-var provider.","commonSituations":"API key/header resolution where the configured value calls a template string (e.g. myFunc(...)) defined in the BAML project; running resolution before the IR is loaded.","solutions":["Call resolve_with_templates() with a TemplateStringRenderer implementation instead of resolve().","Load/construct the IR before resolving expressions that may contain template string calls.","If only env-var substitution is needed, rewrite the config value to avoid template string calls."],"exampleFix":"// before\nlet key = expr.resolve(&env)?;\n// after\nlet key = expr.resolve_with_templates(&env, &renderer)?;","handlingStrategy":"type-guard","validationCode":"if matches!(expr, ValueExpr::TemplateStringCall { .. }) { /* must use resolve_with_templates */ }","typeGuard":"fn needs_ir(e: &ValueExpr) -> bool { matches!(e, ValueExpr::TemplateStringCall { .. }) }","tryCatchPattern":"let v = expr.resolve_with_templates(&env, &renderer)?;","preventionTips":["Load the BAML IR before resolving config expressions","Prefer resolve_with_templates for any user-authored value","Restrict configs to env-var/literal values when IR is unavailable"],"tags":["rust","templates","ir"],"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"}