{"record":{"id":"d513a0c735bd8905","repo":"BoundaryML/baml","slug":"expected-a-boolean","errorCode":null,"errorMessage":"Expected a boolean","messagePattern":"Expected a boolean","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-types/src/value_expr.rs","lineNumber":548,"sourceCode":"            Self::Map(..) => anyhow::bail!(\"Expected a string, not a map\"),\n            Self::Null(..) => anyhow::bail!(\"Expected a string, not null\"),\n            Self::ClassConstructor(..) => {\n                anyhow::bail!(\"Expected a string, not a class constructor\")\n            }\n        }\n    }\n\n    pub fn resolve_string(&self, ctx: &impl GetEnvVar) -> Result<String> {\n        match self.resolve(ctx) {\n            Ok(ResolvedValue::String(s, ..)) => Ok(s),\n            _ => Err(anyhow::anyhow!(\"Expected a string\")),\n        }\n    }\n\n    pub fn resolve_bool(&self, ctx: &impl GetEnvVar) -> Result<bool> {\n        match self.resolve(ctx) {\n            Ok(ResolvedValue::Bool(b, ..)) => Ok(b),\n            _ => Err(anyhow::anyhow!(\"Expected a boolean\")),\n        }\n    }\n\n    pub fn resolve_array(&self, ctx: &impl GetEnvVar) -> Result<Vec<ResolvedValue>> {\n        match self.resolve(ctx) {\n            Ok(ResolvedValue::Array(a, ..)) => Ok(a),\n            _ => Err(anyhow::anyhow!(\"Expected an array\")),\n        }\n    }\n\n    pub fn resolve_map(&self, ctx: &impl GetEnvVar) -> Result<IndexMap<String, ResolvedValue>> {\n        match self.resolve(ctx) {\n            Ok(ResolvedValue::Map(m, ..)) => Ok(m.into_iter().map(|(k, (_, v))| (k, v)).collect()),\n            _ => Err(anyhow::anyhow!(\"Expected a map\")),\n        }\n    }\n\n    pub fn resolve_numeric(&self, ctx: &impl GetEnvVar) -> Result<String> {","sourceCodeStart":530,"sourceCodeEnd":566,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-types/src/value_expr.rs#L530-L566","documentation":"resolve_bool resolves an UnresolvedValue at runtime and requires the result to be ResolvedValue::Bool; any other resolved variant (or a resolution failure such as an unset env var) produces this error. It enforces that the field truly evaluates to a boolean rather than coercing truthy values.","triggerScenarios":"Calling resolve_bool(ctx) where resolve(ctx) returns a non-Bool ResolvedValue — e.g. the BAML field is the string \"true\", a number 1, or an env::VAR whose value is not a boolean literal.","commonSituations":"Setting boolean options via env vars (env::ENABLE_X) where the env value is \"1\"/\"yes\" instead of BAML boolean literals true/false, or quoting booleans as strings by mistake.","solutions":["Author the value as a bare boolean literal (true/false) in .baml, not \"true\" or 1","If driven by an env var, ensure its value is exactly true or false, or convert in code after resolve_string","Use resolve_string and parse manually when the source cannot be changed to a boolean type"],"exampleFix":"// before (baml)\noptions {\n  stream \"true\"\n}\n// after (baml)\noptions {\n  stream true\n}","handlingStrategy":"validation","validationCode":"// Rust\nmatch value.resolve(&ctx) {\n    Ok(ResolvedValue::Bool(_)) => {},\n    Ok(ResolvedValue::String(s, _)) => {\n        anyhow::ensure!(s == \"true\" || s == \"false\", \"field must be boolean, got string {s}\");\n    }\n    _ => anyhow::bail!(\"field must resolve to a boolean\"),\n}","typeGuard":"fn resolves_to_bool(v: &UnresolvedValue<()>, ctx: &EvaluationContext) -> bool {\n    matches!(v.resolve(ctx), Ok(ResolvedValue::Bool(..)))\n}","tryCatchPattern":"// Rust\nlet b = value.resolve_bool(&ctx)\n    .with_context(|| format!(\"field '{name}' must be true/false (unquoted), not a string or number\"))?;","preventionTips":["Write booleans unquoted in .baml (true/false)","For env-driven flags, ensure env values are exactly true/false or parse them yourself","Never rely on truthy coercion of strings or numbers"],"tags":["rust","baml","type-mismatch","boolean"],"backgroundTag":"type-mismatch","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"}