{"record":{"id":"4bbbecb18142c7cc","repo":"BoundaryML/baml","slug":"unsupported-types-for-operator-at-4bbbec","errorCode":null,"errorMessage":"unsupported types for % operator at {:?}","messagePattern":"unsupported types for % operator at (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2432,"sourceCode":"                }\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\n                .map(|ord| matches!(ord, std::cmp::Ordering::Less))\n                .ok_or_else(|| anyhow!(\"unsupported types for < operator at {:?}\", meta.0))?;\n            BamlValueWithMeta::Bool(less, meta.clone())\n        }","sourceCodeStart":2414,"sourceCodeEnd":2450,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2414-L2450","documentation":"The interpreter implements `%` (modulo) only for two Int operands; any other combination (float, string, bool, arrays, etc.) hits this catch-all bail in evaluate_binary_op's Mod arm. Use `/` for floats, or cast operands to Int if truncation is acceptable.","triggerScenarios":"Evaluating `a % b` where a or b is a Float, String, Bool, or non-numeric value instead of Int — e.g. `x % 2` where x is a float field, or `count % divisor` where count came from a string.","commonSituations":"Float modulo attempted after float division; string values from LLM output used directly in `%`; numeric values stored in untyped containers (maps/arrays) and used in modulo without casting.","solutions":["Cast operands to int: `a as int % b as int`","Replace float modulo with an equivalent arithmetic expression or refactor to integer math","Inspect operand types before the operation (print them) to find the non-Int value","Parse string values to int before arithmetic"],"exampleFix":"// before (.baml)\nlet isOdd = count % 2; // count: float\n// after (.baml)\nlet isOdd = count as int % 2;","handlingStrategy":"type-guard","validationCode":"// .baml — coerce to int before modulo\nlet countInt = count as int;\nlet isOdd = countInt % 2;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat `%` as an int-only operator in BAML and cast operands explicitly","Keep values used in modulo typed as int end-to-end (schema, variables)","Avoid pulling modulo operands from untyped maps/arrays without casting","Validate parsed numeric strings before arithmetic"],"tags":["baml","interpreter","modulo","type-error","unsupported-operation"],"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"}