{"record":{"id":"f7ca65847f7c735f","repo":"BoundaryML/baml","slug":"unsupported-types-for-operator-at-f7ca65","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":2423,"sourceCode":"            (BamlValueWithMeta::Float(a, _), BamlValueWithMeta::Float(b, _)) => {\n                if b == 0.0 {\n                    bail!(\"division by zero at {:?}\", meta.0);\n                }\n                BamlValueWithMeta::Float(a / b, meta.clone())\n            }\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());","sourceCodeStart":2405,"sourceCodeEnd":2441,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2405-L2441","documentation":"The interpreter's `/` operator only supports numeric operand pairs (Int or Float in any combination). Any other operand type — string, bool, array, map, class instance, null, etc. — falls through to this catch-all bail in evaluate_binary_op. This indicates a type error in the BAML expression, not a numeric problem.","triggerScenarios":"Evaluating a `/` expression where either operand is not Int/Float: e.g. `\"10\" / 2` (string numerator), dividing by a string, a bool used as a number, dividing arrays or class instances, or a variable whose declared/inferred type is not numeric.","commonSituations":"LLM output returned as a string that was never parsed to a number before division; mixing a numeric field from a class with a string field; using a value from a map (which may be untyped/string) in arithmetic; forgetting an `as int` / `as float` cast after parsing text.","solutions":["Cast operands to numbers first: `str_val as int` or `str_val as float` before dividing","Print the types/values of both operands just before the division to see which is non-numeric","If the value comes from LLM output, parse it (e.g. via a numeric-typed schema field or explicit cast) instead of using the raw string","Ensure class fields/map values used in arithmetic are declared as int/float"],"exampleFix":"// before (.baml)\nlet half = input_value / 2; // input_value is a string\n// after (.baml)\nlet half = input_value as int / 2;","handlingStrategy":"type-guard","validationCode":"// .baml — ensure numeric operands before dividing\nlet a = input_value as float;\nlet b = divisor as float;\nif b == 0.0 { return 0.0; }\nlet q = a / b;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cast string values from LLM output (`as int`/`as float`) before arithmetic","Declare schema fields as int/float when they will be used numerically","Avoid arithmetic directly on map values or untyped containers without casting","Print operand values/types when debugging interpreter type errors"],"tags":["baml","interpreter","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"}