{"record":{"id":"1c6462a5ef7a9189","repo":"BoundaryML/baml","slug":"expected-a-string-not-a-map","errorCode":null,"errorMessage":"Expected a string, not a map","messagePattern":"Expected a string, not a map","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-types/src/value_expr.rs","lineNumber":530,"sourceCode":"}\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),\n            _ => Err(anyhow::anyhow!(\"Expected a boolean\")),","sourceCodeStart":512,"sourceCodeEnd":548,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-types/src/value_expr.rs#L512-L548","documentation":"as_static_str expects a string-typed UnresolvedValue; a Map (BAML object literal with key/value pairs) cannot be returned as &str, so it bails. The library throws this to keep static string reads type-safe rather than implicitly serializing objects.","triggerScenarios":"Calling as_static_str() on UnresolvedValue::Map(..) — a BAML field authored as an object/map literal ({ key: \"value\" }) but read through the string accessor.","commonSituations":"Nesting config by mistake (e.g. putting an options object where a scalar string belongs), or JSON-style config copied into a field that must be a plain string.","solutions":["Replace the map literal with the specific string field/value required","Read the field with resolve_map(ctx) and extract the needed entry in code","Align the .baml schema so the field's declared type matches the authored value"],"exampleFix":"// before (baml)\noptions {\n  model { name: \"gpt-4o\" }\n}\n// after (baml)\noptions {\n  model \"gpt-4o\"\n}","handlingStrategy":"validation","validationCode":"// Rust\nif matches!(v, UnresolvedValue::Map(..)) {\n    anyhow::bail!(\"expected a string field, got an object/map\");\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":["Keep scalar fields scalar; nest objects only where the schema allows","Use resolve_map for structured fields","Lint baml_src for object literals in string-typed positions"],"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"}