{"record":{"id":"b628ec86960bd4ec","repo":"BoundaryML/baml","slug":"expected-a-numeric-value","errorCode":null,"errorMessage":"Expected a numeric value","messagePattern":"Expected a numeric value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-types/src/value_expr.rs","lineNumber":569,"sourceCode":"\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> {\n        let value = self.resolve(ctx)?;\n        let value: serde_json::Value = value.try_into()?;\n        match serde_json::from_value(value) {\n            Ok(v) => Ok(v),\n            Err(e) => Err(anyhow::anyhow!(\"Failed to deserialize value: {e}\")),\n        }\n    }","sourceCodeStart":551,"sourceCodeEnd":587,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-types/src/value_expr.rs#L551-L587","documentation":"ValueExpr::resolve_numeric resolves an expression and requires the result to be ResolvedValue::Numeric, returning its textual numeric value. If the expression resolves to a non-numeric variant or fails to resolve, the method throws 'Expected a numeric value' and drops the underlying cause.","triggerScenarios":"Calling resolve_numeric on an expression that resolves to a string, array, map, or null — e.g. a numeric config field (temperature, max_tokens, retries) interpolated from an unset or non-numeric env var, or quoted in config.","commonSituations":"Setting TEMPERATURE=\"warm\" in the environment, quoting numbers so they resolve as strings, or leaving the env var unset so resolution falls through to a non-numeric branch.","solutions":["Inspect the raw resolved value via resolve() to see what type it actually is.","Ensure the config value is unquoted numeric (temperature 0.7).","If from an env var, set it to a plain number (TEMPERATURE=0.7) and verify it is not empty.","Provide a numeric default in the config so missing env vars still resolve to Numeric.","Match on resolve() at the call site for a clearer error when scalars are possible."],"exampleFix":"// before (env TEMPERATURE=warm)\nlet t = expr.resolve_numeric(&ctx)?; // Err: Expected a numeric value\n// after\n// TEMPERATURE=0.7 (unquoted numeric) or config: temperature 0.7\nlet t = expr.resolve_numeric(&ctx)?;","handlingStrategy":"validation","validationCode":"let resolved = expr.resolve(&ctx)?;\nif !matches!(resolved, ResolvedValue::Numeric(_)) {\n    bail!(\"value is not numeric: {resolved:?}\");\n}\nlet n = expr.resolve_numeric(&ctx)?;","typeGuard":"fn is_numeric(v: &ResolvedValue) -> bool { matches!(v, ResolvedValue::Numeric(..)) }","tryCatchPattern":"let n = match expr.resolve_numeric(&ctx) {\n    Ok(n) => n,\n    Err(_) => \"0\".to_string(), // safe default\n};","preventionTips":["Keep numeric config values unquoted and numeric (0.7, not \"0.7\").","Set env vars to plain numbers without units or whitespace.","Provide numeric defaults in config for env-sourced fields.","Reject non-numeric strings early at config parse time."],"tags":["rust","baml","type-mismatch","numeric"],"backgroundTag":"type-mismatch","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}