{"record":{"id":"2a869d53b88b59d7","repo":"BoundaryML/baml","slug":"expected-an-array","errorCode":null,"errorMessage":"Expected an array","messagePattern":"Expected an array","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-types/src/value_expr.rs","lineNumber":555,"sourceCode":"\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> {\n        match self.resolve(ctx) {\n            Ok(ResolvedValue::Numeric(n, ..)) => Ok(n),\n            _ => Err(anyhow::anyhow!(\"Expected a numeric value\")),\n        }\n    }\n\n    pub fn resolve_null(&self, ctx: &impl GetEnvVar) -> Result<()> {","sourceCodeStart":537,"sourceCodeEnd":573,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-types/src/value_expr.rs#L537-L573","documentation":"In BAML's baml-types crate, ValueExpr::resolve_array resolves a value expression and requires the result to be ResolvedValue::Array. When the expression resolves to any other variant (string, map, number, null, etc.), or resolution fails, the method discards the underlying cause and throws the generic message 'Expected an array'.","triggerScenarios":"Calling ValueExpr::resolve_array(ctx) on an expression whose resolved value is not an array — e.g. a literal string, map, numeric, or null, or an expression that failed to resolve (env var missing, template error). The catch-all arm swallows the inner resolve(ctx) error.","commonSituations":"BAML config code that reads a list field (e.g. a list of clients or tests) but the evaluated value came from an env var or single literal that is not a JSON array; a config migration changed a field from list to scalar.","solutions":["Print or resolve the same expression with resolve() to inspect the actual ResolvedValue and confirm its variant before calling resolve_array.","If the value may be a scalar, change the config so the field is a JSON array (e.g. [\"gpt-4o\"] not \"gpt-4o\").","If the source is an env var, ensure it is set and the config default wraps values in brackets.","Fix any failing resolve() cause first (env var availability), since its message is currently swallowed.","At your own call sites, match on resolve() and produce a precise error instead of resolve_array."],"exampleFix":"// before (env VALUE = \"a,b\")\nlet items = expr.resolve_array(&ctx)?; // Err: Expected an array\n// after\n// VALUE='[\"a\",\"b\"]' (or config default '[\"a\",\"b\"]') so the expression resolves to an array\nlet items = expr.resolve_array(&ctx)?;","handlingStrategy":"validation","validationCode":"let resolved = expr.resolve(&ctx)?;\nif !matches!(resolved, ResolvedValue::Array(_)) {\n    bail!(\"value is not an array: {resolved:?}\");\n}\nlet items = expr.resolve_array(&ctx)?;","typeGuard":"fn is_array(v: &ResolvedValue) -> bool { matches!(v, ResolvedValue::Array(..)) }","tryCatchPattern":"match expr.resolve_array(&ctx) {\n    Ok(items) => items,\n    Err(_) => default_items(), // fallback + log\n}","preventionTips":["Ensure list-typed config fields are JSON arrays, not scalars.","When values come from env vars, wrap them as JSON arrays in the config default.","Call resolve() first while debugging to see the actual variant.","Don't quote array values in config files."],"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"}