{"record":{"id":"59d112d98d13a40f","repo":"BoundaryML/baml","slug":"field-name-int-is-outside-baml-int-range-got","errorCode":null,"errorMessage":"`{field_name}: int` is outside BAML int range [{}, {}], got {}","messagePattern":"`(.+?): int` is outside BAML int range \\[(.+?), (.+?)\\], got (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"baml_language/crates/baml_builtins2_codegen/src/codegen.rs","lineNumber":641,"sourceCode":"        | BamlType::Generic(_)\n        | BamlType::Named(_)\n        | BamlType::Media(_) => \"bex_vm_types::Value\".to_string(),\n    }\n}\n\n/// Generate the expression to convert a copy struct field to a Value.\nfn copy_field_to_value(field_name: &str, ty: &BamlType) -> String {\n    match ty {\n        BamlType::RustType => {\n            format!(\"bex_vm_types::Value::object(vm.alloc_rust_data(self.{field_name}))\")\n        }\n        // `to_value` has no error channel (`fn to_value(self, vm) -> Value`),\n        // so an out-of-i63 native i64 reaches this path only when caller-side\n        // Rust constructed a struct field that violates the i63 BAML\n        // contract. Fail loudly in *both* debug and release rather than\n        // truncating silently via `Value::int`'s `debug_assert`.\n        BamlType::Int => format!(\n            \"bex_vm_types::Value::try_int(self.{field_name}).unwrap_or_else(|| panic!(\\\n                \\\"`{field_name}: int` is outside BAML int range [{{}}, {{}}], got {{}}\\\", \\\n                bex_vm_types::Value::INT_MIN, bex_vm_types::Value::INT_MAX, self.{field_name}))\"\n        ),\n        // Bigints are always heap-allocated, and allocation is fallible (the\n        // value may exceed `MAX_BIGINT_BITS`). `to_value` has no error channel,\n        // so — like the `int` range case above — fail loudly rather than\n        // silently dropping the overflow. The panic reports the bit count from\n        // `VmPanic::AllocFailure` (`{p}`), never the bigint itself, which could\n        // be millions of digits long.\n        BamlType::Bigint => format!(\n            \"vm.try_alloc_bigint(self.{field_name}).unwrap_or_else(|p| panic!(\\\n                \\\"failed to allocate bigint field `{field_name}`: {{p}}\\\"))\"\n        ),\n        BamlType::Float => {\n            format!(\"bex_vm_types::Value::object(vm.alloc_float(self.{field_name}))\")\n        }\n        BamlType::Bool => format!(\"bex_vm_types::Value::bool(self.{field_name})\"),\n        BamlType::Null => \"bex_vm_types::Value::NULL\".to_string(),","sourceCodeStart":623,"sourceCodeEnd":659,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_builtins2_codegen/src/codegen.rs#L623-L659","documentation":"Generated struct-copy code panics when a native i64 field value falls outside BAML's i63 int range (Value::INT_MIN..INT_MAX). Because `to_value` has no error channel, the generated code uses `Value::try_int(...).unwrap_or_else(|| panic!(...))` so the violation fails loudly in both debug and release rather than being silently truncated. This indicates a caller-side Rust bug that constructed an out-of-contract field value.","triggerScenarios":"emit_copy_struct -> copy_field_to_value generating code for a `field_name: int` struct field whose runtime i64 value exceeds Value::INT_MAX or is below Value::INT_MIN; calling to_value on a struct built by hand in Rust with such a value.","commonSituations":"Interop code computing large i64 values (timestamps in nanos, hash values, counters) and passing them directly into BAML struct fields; misunderstanding that BAML `int` is 63-bit, not full i64.","solutions":["Clamp or validate the field value against bex_vm_types::Value::INT_MIN/INT_MAX before constructing the struct.","Store the value as a BAML bigint (try_alloc_bigint) if it genuinely needs more than i63.","Fix the producing code so the field stays within the i63 contract."],"exampleFix":"// before\nMyStruct { counter: huge_i64 }\n// after\nassert!(huge_i64 >= bex_vm_types::Value::INT_MIN && huge_i64 <= bex_vm_types::Value::INT_MAX);\nMyStruct { counter: huge_i64 }","handlingStrategy":"validation","validationCode":"fn fits_baml_int(v: i64) -> bool {\n    v >= bex_vm_types::Value::INT_MIN && v <= bex_vm_types::Value::INT_MAX\n}","typeGuard":null,"tryCatchPattern":"// This is a panic, not a Result; validate before constructing\nassert!(fits_baml_int(v), \"field exceeds BAML i63 range: {v}\");","preventionTips":["Remember BAML `int` is 63-bit, not full i64.","Range-check values crossing the Rust->VM boundary.","Use bigint fields for values that can exceed i63.","Cover interop code with range assertions in tests."],"tags":["panic","integer-overflow","codegen","range"],"backgroundTag":"value-out-of-range","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"}