{"record":{"id":"dca68934cd6a5ba4","repo":"BoundaryML/baml","slug":"modulo-by-zero-at","errorCode":null,"errorMessage":"modulo by zero at {:?}","messagePattern":"modulo by zero at (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2428,"sourceCode":"            }\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Float(b, _)) => {\n                if b == 0.0 {\n                    bail!(\"division by zero at {:?}\", meta.0);\n                }\n                BamlValueWithMeta::Float((a as f64) / b, meta.clone())\n            }\n            (BamlValueWithMeta::Float(a, _), BamlValueWithMeta::Int(b, _)) => {\n                if b == 0 {\n                    bail!(\"division by zero at {:?}\", meta.0);\n                }\n                BamlValueWithMeta::Float(a / (b as f64), meta.clone())\n            }\n            _ => bail!(\"unsupported types for / operator at {:?}\", meta.0),\n        },\n        BinaryOperator::Mod => match (left_val.clone(), right_val.clone()) {\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {\n                if b == 0 {\n                    bail!(\"modulo by zero at {:?}\", meta.0);\n                }\n                BamlValueWithMeta::Int(a % b, meta.clone())\n            }\n            _ => bail!(\"unsupported types for % operator at {:?}\", meta.0),\n        },\n\n        // Comparison operations\n        BinaryOperator::Eq => {\n            let equal = values_equal(&left_val.clone(), &right_val.clone());\n            BamlValueWithMeta::Bool(equal, meta.clone())\n        }\n        BinaryOperator::Neq => {\n            let not_equal = !values_equal(&left_val.clone(), &right_val.clone());\n            BamlValueWithMeta::Bool(not_equal, meta.clone())\n        }\n        BinaryOperator::Lt => {\n            let ord_opt = compare_values(&left_val.clone(), &right_val.clone())?;\n            let less = ord_opt","sourceCodeStart":2410,"sourceCodeEnd":2446,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2410-L2446","documentation":"The BAML `%` (modulo) operator supports only the (Int, Int) operand pair in this interpreter. A zero integer denominator also raises 'modulo by zero', and any non-Int operand pair reaches this catch-all bail. Modulo by zero is mathematically undefined, and float/string operands are not implemented for `%`.","triggerScenarios":"Evaluating `a % b` where: (1) both operands are Int but b == 0 (raises the 'modulo by zero' variant at the same site), or (2) either operand is Float/String/etc. (raises this 'unsupported types for % operator' message). Both surface from the same Mod arm of evaluate_binary_op.","commonSituations":"Applying `%` to floats (e.g. `3.5 % 2`), computing parity on a string-parsed number, modulo on values from a map or LLM output that arrived as strings, or `% 0` from an unset/defaulting variable.","solutions":["Use integers on both sides: cast with `as int` if needed (for floats consider `a - (a / b) * b` or refactor)","Check the divisor is non-zero before applying `%`","Print both operands/types before the operation to identify the offending type","If a string from LLM output, parse to int first"],"exampleFix":"// before (.baml)\nlet rem = value % 2.0; // float not supported\n// after (.baml)\nlet rem = value as int % 2;","handlingStrategy":"validation","validationCode":"// .baml — ints only, non-zero divisor\nlet bi = b as int;\nif bi == 0 { return 0; }\nlet rem = (a as int) % bi;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use `%` only on integers; cast floats/strings with `as int` first","Check the divisor is non-zero before every modulo","Replace float modulo needs with refactored integer logic or explicit arithmetic","Parse LLM-produced numbers to int before applying `%`"],"tags":["baml","interpreter","modulo","type-error","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}