{"record":{"id":"566e9c4f397bc81f","repo":"BoundaryML/baml","slug":"expected-a-map","errorCode":null,"errorMessage":"Expected a map","messagePattern":"Expected a map","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-types/src/value_expr.rs","lineNumber":562,"sourceCode":"\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<()> {\n        match self.resolve(ctx) {\n            Ok(ResolvedValue::Null(..)) => Ok(()),\n            _ => Err(anyhow::anyhow!(\"Expected a null value\")),\n        }\n    }\n\n    pub fn resolve_serde<T: serde::de::DeserializeOwned>(&self, ctx: &impl GetEnvVar) -> Result<T> {","sourceCodeStart":544,"sourceCodeEnd":580,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-types/src/value_expr.rs#L544-L580","documentation":"ValueExpr::resolve_map resolves an expression and requires the result to be ResolvedValue::Map. Any other resolved variant (or a resolution failure whose message is dropped) yields the generic error 'Expected a map'. The underlying resolve() error is not chained, so the real cause is hidden.","triggerScenarios":"Calling resolve_map on an expression that evaluates to a list, string, numeric, or null — e.g. a map-valued config field sourced from an env var that is unset or holds non-object JSON.","commonSituations":"Config sections expected to be key/value objects (params, metadata, headers) where the user supplied a scalar, or the interpolating env var is missing.","solutions":["Resolve the expression with resolve() to see the actual variant and the real failure cause.","Ensure the config value is an object/map (JSON object syntax: {\"k\": \"v\"}).","If sourced from an env var, verify the variable is set and contains a JSON object.","Add a fallback/default map in config when the value may be absent.","Handle the error with context: match on resolve() yourself to surface the inner message."],"exampleFix":"// before (env PARAMS unset)\nlet m = expr.resolve_map(&ctx)?; // Err: Expected a map\n// after\n// PARAMS='{\"temperature\":0.7}' or config default: {\"temperature\": 0.7}\nlet m = expr.resolve_map(&ctx)?;","handlingStrategy":"validation","validationCode":"let resolved = expr.resolve(&ctx)?;\nif !matches!(resolved, ResolvedValue::Map(_)) {\n    bail!(\"value is not a map: {resolved:?}\");\n}\nlet m = expr.resolve_map(&ctx)?;","typeGuard":"fn is_map(v: &ResolvedValue) -> bool { matches!(v, ResolvedValue::Map(..)) }","tryCatchPattern":"let m = expr.resolve_map(&ctx).unwrap_or_else(|_| IndexMap::new());","preventionTips":["Write object-valued config fields as JSON objects with string keys.","Verify interpolated env vars are set and hold JSON objects.","Check that migrations didn't turn map fields into scalars.","Surface the inner resolve() error in your own call sites for debuggability."],"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"}