{"record":{"id":"f89a5f6ca09431d1","repo":"BoundaryML/baml","slug":"expected-a-string-not-an-array","errorCode":null,"errorMessage":"Expected a string, not an array","messagePattern":"Expected a string, not an array","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-types/src/value_expr.rs","lineNumber":528,"sourceCode":"        }\n    }\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) {","sourceCodeStart":510,"sourceCodeEnd":546,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-types/src/value_expr.rs#L510-L546","documentation":"as_static_str is a string-typed accessor: when the UnresolvedValue holds an Array, there is no string to return, so it bails. This guards against silently coercing a list value into a string where the BAML schema expects a string field.","triggerScenarios":"Calling as_static_str() on UnresolvedValue::Array(..) — the BAML field was authored as a list (e.g. [\"a\", \"b\"] or [1,2]) but the consuming API reads it as a single string.","commonSituations":"Config mistakes where a developer supplies a list where one value is expected (e.g. multiple model names, a list of stop sequences placed in a scalar field), or schema evolution changed the field type.","solutions":["Change the BAML value to a single quoted string","If a list is genuinely intended, read the field with resolve_array(ctx) and pick/serialize the element you need","Fix the consuming code to match the field's declared type (string vs list)"],"exampleFix":"// before (baml)\noptions {\n  model [\"gpt-4o\"]\n}\n// after (baml)\noptions {\n  model \"gpt-4o\"\n}","handlingStrategy":"validation","validationCode":"// Rust\nif matches!(v, UnresolvedValue::Array(..)) {\n    anyhow::bail!(\"expected a single string, got a list\");\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":["Check field cardinality in .baml schema before authoring values","Use resolve_array when lists are legitimate","Avoid copy-pasting list-shaped config into scalar fields"],"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"}