{"record":{"id":"37d825711e5f7d49","repo":"BoundaryML/baml","slug":"invalid-numeric-value","errorCode":null,"errorMessage":"Invalid numeric value: {}","messagePattern":"Invalid numeric value: (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-core/src/ir/repr.rs","lineNumber":368,"sourceCode":"        match self {\n            ast::Expression::BoolValue(val, span) => Ok(Expr::Atom(BamlValueWithMeta::Bool(\n                *val,\n                (span.clone(), Some(TypeIR::bool())),\n            ))),\n            ast::Expression::NumericValue(val, span) => {\n                // Prefer int when it parses cleanly; otherwise fall back to float.\n                if let Ok(v) = val.parse::<i64>() {\n                    Ok(Expr::Atom(BamlValueWithMeta::Int(\n                        v,\n                        (span.clone(), Some(TypeIR::int())),\n                    )))\n                } else if let Ok(f) = val.parse::<f64>() {\n                    Ok(Expr::Atom(BamlValueWithMeta::Float(\n                        f,\n                        (span.clone(), Some(TypeIR::float())),\n                    )))\n                } else {\n                    Err(anyhow!(\"Invalid numeric value: {}\", val))\n                }\n            }\n            ast::Expression::StringValue(val, span) => Ok(Expr::Atom(BamlValueWithMeta::String(\n                val.to_string(),\n                (span.clone(), Some(TypeIR::string())),\n            ))),\n            ast::Expression::RawStringValue(val) => Ok(Expr::Atom(BamlValueWithMeta::String(\n                val.value().to_string(),\n                (val.span().clone(), Some(TypeIR::string())),\n            ))),\n            ast::Expression::JinjaExpressionValue(val, span) => Ok(Expr::Atom(\n                BamlValueWithMeta::String(val.to_string(), (span.clone(), Some(TypeIR::string()))),\n            )),\n            ast::Expression::Array(vals, span) => {\n                let new_items = vals\n                    .iter()\n                    .map(|v| v.repr(db))\n                    .collect::<Result<Vec<_>>>()?;","sourceCodeStart":350,"sourceCodeEnd":386,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-core/src/ir/repr.rs#L350-L386","documentation":"When converting AST numeric literals into IR expressions, BAML first tries parsing as an integer and then as an f64 float. If the literal parses as neither, it raises 'Invalid numeric value'. This guards against malformed numbers reaching the IR.","triggerScenarios":"repr(db) on an ast::Expression::NumberValue whose text cannot be parsed by Rust's i64 or f64 parsers — e.g. literals with invalid characters, multiple decimal points, or unsupported numeric syntax like hex/underscores where unsupported.","commonSituations":"Hand-edited numeric literals in .baml files with typos (e.g. '1.2.3', '12_000'); pasting numbers from other languages with unsupported suffixes or formats.","solutions":["Locate the numeric literal named in the error and correct its syntax.","Replace unsupported formats (underscores, suffixes, hex) with plain decimal notation.","Split invalid multi-dot values or quote them as strings if they are identifiers-like."],"exampleFix":"// before\nretry_policy p {\n  max_retries 1.2.3\n}\n// after\nretry_policy p {\n  max_retries 3\n}","handlingStrategy":"validation","validationCode":"# validate numeric literals in .baml before compiling\nimport re\nfor tok in re.findall(r'(?<![\\w.])\\d[\\d.\\w_]*', src):\n    try:\n        int(tok) if '.' not in tok and 'e' not in tok.lower() else float(tok)\n    except ValueError:\n        print(f\"invalid numeric literal: {tok}\")","typeGuard":null,"tryCatchPattern":"match expr_repr(db) {\n    Ok(e) => e,\n    Err(e) if e.to_string().starts_with(\"Invalid numeric value\") => {\n        eprintln!(\"correct the malformed numeric literal in the .baml file\");\n        return Err(e);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Write numeric literals as plain decimals (no suffixes/underscores).","Avoid hand-editing numbers without re-running baml generate.","Lint .baml files in CI for malformed literals."],"tags":["baml","parser","numeric","schema"],"backgroundTag":"invalid-argument-format","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"}