{"record":{"id":"6fa159f940255dde","repo":"BoundaryML/baml","slug":"failed-to-resolve-expression-with-error","errorCode":null,"errorMessage":"Failed to resolve expression {:?} with error: {:?}","messagePattern":"Failed to resolve expression (.+?) with error: (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/types/runtime_context.rs","lineNumber":128,"sourceCode":"            type_alias_overrides,\n            recursive_type_alias_overrides,\n            call_id_stack,\n            recursive_class_overrides,\n            is_modular_api: false,\n        }\n    }\n\n    pub fn resolve_expression<T: serde::de::DeserializeOwned>(\n        &self,\n        expr: &UnresolvedValue<()>,\n        // If true, will return an error if any environment variables are not set\n        // otherwise, will return a value with the missing environment variables replaced with the string \"${key}\"\n        strict: bool,\n    ) -> Result<T> {\n        let ctx = EvaluationContext::new(&self.env, strict);\n        match expr.resolve_serde::<T>(&ctx) {\n            Ok(v) => Ok(v),\n            Err(e) => anyhow::bail!(\n                \"Failed to resolve expression {:?} with error: {:?}\",\n                expr,\n                e\n            ),\n        }\n    }\n}\n","sourceCodeStart":110,"sourceCodeEnd":136,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/types/runtime_context.rs#L110-L136","documentation":"resolve_expression failed to evaluate a runtime context expression (typically an environment-variable interpolation like ${MY_VAR}) into the requested type T, and wraps the resolver error with the expression text for diagnosis. The library throws this whenever expr.resolve_serde against the EvaluationContext (env vars, with the given strict mode) fails.","triggerScenarios":"Calling RuntimeContext::resolve_expression::<T> with an expression referencing a missing environment variable (non-strict mode leaves placeholders), or an expression whose resolved value cannot deserialize into T.","commonSituations":"BAML clients referencing ${OPENAI_API_KEY} or similar in config where the env var is unset or the value type doesn't match what the client expects (e.g. number vs string).","solutions":["Set the missing environment variable the expression references","Check the expression's value type matches the target parameter (string vs int)","Fix the expression syntax in the BAML file","Run with strict resolution to surface all unresolved variables early"],"exampleFix":"// before\nexport BAML_LOG=info\n// after\nexport OPENAI_API_KEY=sk-...\nexport BAML_LOG=info","handlingStrategy":"validation","validationCode":"// ensure all env vars referenced in expressions exist before resolving\nconst required = ['OPENAI_API_KEY', 'MODEL_NAME'];\nfor (const k of required) {\n  if (!process.env[k]) throw new Error(`missing env var for BAML expression: ${k}`);\n}","typeGuard":null,"tryCatchPattern":"match ctx.resolve_expression::<String>(&expr) {\n  Ok(v) => v,\n  Err(e) => { eprintln!(\"check env vars / expression syntax: {e}\"); return Err(e); }\n}","preventionTips":["Keep all ${VAR} references backed by a .env file loaded at startup","Validate expression value types match client parameter types (string vs int)","Run baml-cli with strict env checking in CI to fail fast on missing vars"],"tags":["environment","expression-resolution","config","rust"],"backgroundTag":"missing-env-var","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"}