{"record":{"id":"5f89c26ff6b10579","repo":"BoundaryML/baml","slug":"invalid-number-n","errorCode":null,"errorMessage":"Invalid number: {n}","messagePattern":"Invalid number: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/optimize/gepa_runtime.rs","lineNumber":398,"sourceCode":"        serde_json::to_string_pretty(&version_info).context(\"Failed to serialize version info\")?;\n\n    std::fs::write(version_file, version_json).context(\"Failed to write .gepa_version\")?;\n\n    Ok(())\n}\n\n/// Convert serde_json::Value to BamlValue\nfn json_to_baml_value(val: serde_json::Value) -> Result<BamlValue> {\n    match val {\n        serde_json::Value::Null => Ok(BamlValue::Null),\n        serde_json::Value::Bool(b) => Ok(BamlValue::Bool(b)),\n        serde_json::Value::Number(n) => {\n            if let Some(i) = n.as_i64() {\n                Ok(BamlValue::Int(i))\n            } else if let Some(f) = n.as_f64() {\n                Ok(BamlValue::Float(f))\n            } else {\n                anyhow::bail!(\"Invalid number: {n}\")\n            }\n        }\n        serde_json::Value::String(s) => Ok(BamlValue::String(s)),\n        serde_json::Value::Array(arr) => {\n            let items: Result<Vec<_>> = arr.into_iter().map(json_to_baml_value).collect();\n            Ok(BamlValue::List(items?))\n        }\n        serde_json::Value::Object(obj) => {\n            let map: Result<indexmap::IndexMap<_, _>> = obj\n                .into_iter()\n                .map(|(k, v)| json_to_baml_value(v).map(|bv| (k, bv)))\n                .collect();\n            Ok(BamlValue::Map(map?))\n        }\n    }\n}\n\n/// Convert BamlValue to serde_json::Value","sourceCodeStart":380,"sourceCodeEnd":416,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/optimize/gepa_runtime.rs#L380-L416","documentation":"The GEPA optimizer converts JSON test-case values into BamlValue so it can propose improvements and merge prompt variants. serde_json numbers that fit neither i64 nor f64 (e.g. arbitrarily large u64 values beyond f64/i64 range, or NaN-like representations not expressible) fall through both as_i64() and as_f64() and hit this bail. It's an internal conversion guard for numeric JSON inputs that BAML cannot represent.","triggerScenarios":"json_to_baml_value receives a serde_json::Value::Number that is neither as_i64() nor as_f64() — practically, a JSON number larger than i64/f64 can represent (e.g. a u64 > 2^53 or > i64::MAX) while running propose_improvements or merge_variants on test cases.","commonSituations":"Test-case parameters or labels containing huge integer IDs (snowflake/timestamp-millis as raw JSON numbers); hand-edited dataset files with oversized numbers; JSON produced by tooling that serializes big integers natively.","solutions":["Change the value in your test-case JSON to a string (e.g. \"9007199254740993\") and parse it in the function","Reduce the number to fit in i64/f64 range in the dataset","Quote large integers in the optimizer dataset files so they arrive as JSON strings","If this is a bug in your BAML version, upgrade BAML — the converter may have gained big-number support"],"exampleFix":"// before (test case JSON)\n{ \"order_id\": 9223372036854775807 }\n\n// after\n{ \"order_id\": \"9223372036854775807\" }\n// and change the BAML param type to string","handlingStrategy":"validation","validationCode":"function safeNumber(n: unknown): string | number {\n  if (typeof n === 'number') {\n    if (!Number.isSafeInteger(n) && Number.isInteger(n)) return n.toString(); // treat big ints as strings\n    return n;\n  }\n  return n as string;\n}\n// sanitize dataset JSON before handing it to the optimizer","typeGuard":"function isOptimizerSafeNumber(n: number): boolean {\n  return Number.isFinite(n) && (Number.isInteger(n) ? Math.abs(n) <= Number.MAX_SAFE_INTEGER : true);\n}","tryCatchPattern":"try {\n  await optimizer.proposeImprovements(dataset);\n} catch (e) {\n  if (/Invalid number/i.test(e.message)) {\n    console.error('A JSON number in the dataset is out of i64/f64 range; quote large integers as strings');\n  }\n  throw e;\n}","preventionTips":["Serialize large IDs/timestamps as strings in datasets and prompts","Validate dataset JSON number ranges before optimizer runs","Avoid hand-editing numeric fields in optimizer datasets without range checks"],"tags":["json","conversion","numbers","optimizer"],"backgroundTag":"invalid-argument-value","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"}