{"record":{"id":"fdbb623e21dd6ee4","repo":"BoundaryML/baml","slug":"expected-a-string-not-a-bool","errorCode":null,"errorMessage":"Expected a string, not a bool","messagePattern":"Expected a string, not a bool","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-types/src/value_expr.rs","lineNumber":529,"sourceCode":"    }\n}\n\nimpl<Meta> UnresolvedValue<Meta> {\n    pub fn as_static_str(&self) -> Result<&str> {\n        match self {\n            Self::String(StringOr::Value(v), ..) => Ok(v.as_str()),\n            Self::String(StringOr::EnvVar(..), ..) => {\n                anyhow::bail!(\"Expected a statically defined string, not env variable\")\n            }\n            Self::String(StringOr::JinjaExpression(..), ..) => {\n                anyhow::bail!(\"Expected a statically defined string, not expression\")\n            }\n            Self::String(StringOr::TemplateStringCall { .. }, ..) => {\n                anyhow::bail!(\"Expected a statically defined string, not a template_string call\")\n            }\n            Self::Numeric(num, ..) => Ok(num.as_str()),\n            Self::Array(..) => anyhow::bail!(\"Expected a string, not an array\"),\n            Self::Bool(..) => anyhow::bail!(\"Expected a string, not a bool\"),\n            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),","sourceCodeStart":511,"sourceCodeEnd":547,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-types/src/value_expr.rs#L511-L547","documentation":"as_static_str only yields strings; encountering UnresolvedValue::Bool means the field holds true/false where a string is required, so the accessor errors. This prevents accidental boolean-to-string coercion in statically read BAML fields.","triggerScenarios":"Calling as_static_str() on UnresolvedValue::Bool(..) — e.g. a BAML field set to true or false but consumed via a string accessor.","commonSituations":"Misconfiguring a string option (like a model name, header, or tag) with a boolean value, or calling the wrong accessor after a config refactor changed the field's type.","solutions":["Change the BAML value from a boolean literal to the required string literal (e.g. \"true\" only if the schema truly wants text)","Use resolve_bool(ctx) in the consuming code if the value should stay boolean","Correct whichever side (schema or accessor) is wrong so types agree"],"exampleFix":"// before (baml)\noptions {\n  some_flag true\n}\n// after (baml)\noptions {\n  some_flag \"enabled\"\n}","handlingStrategy":"validation","validationCode":"// Rust\nif matches!(v, UnresolvedValue::Bool(..)) {\n    anyhow::bail!(\"expected a string field, got a boolean\");\n}\nlet s = v.as_static_str()?;","typeGuard":"fn is_string_value<Meta>(v: &UnresolvedValue<Meta>) -> bool {\n    matches!(v, UnresolvedValue::String(_, _))\n}","tryCatchPattern":null,"preventionTips":["Match accessor to declared field type (resolve_bool for booleans)","Quote only when the schema truly requires text","Validate .baml config against the schema before runtime"],"tags":["rust","baml","type-mismatch","config"],"backgroundTag":"type-mismatch","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}