{"record":{"id":"cc4d19a0c2ab6ad1","repo":"BoundaryML/baml","slug":"unsupported-types-for-operator-at-cc4d19","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":2448,"sourceCode":"                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        }\n        BinaryOperator::LtEq => {\n            let ord_opt = compare_values(&left_val.clone(), &right_val.clone())?;\n            let less_eq = ord_opt\n                .map(|ord| matches!(ord, std::cmp::Ordering::Less | std::cmp::Ordering::Equal))\n                .ok_or_else(|| anyhow!(\"unsupported types for <= operator at {:?}\", meta.0))?;\n            BamlValueWithMeta::Bool(less_eq, meta.clone())\n        }\n        BinaryOperator::Gt => {\n            let ord_opt = compare_values(&left_val.clone(), &right_val.clone())?;\n            let greater = ord_opt\n                .map(|ord| matches!(ord, std::cmp::Ordering::Greater))\n                .ok_or_else(|| anyhow!(\"unsupported types for > operator at {:?}\", meta.0))?;\n            BamlValueWithMeta::Bool(greater, meta.clone())\n        }\n        BinaryOperator::GtEq => {\n            let ord_opt = compare_values(&left_val.clone(), &right_val.clone())?;","sourceCodeStart":2430,"sourceCodeEnd":2466,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2430-L2466","documentation":"The `<` operator compares operands via compare_values, which returns None when the two values are not comparable (different types, or a type with no ordering such as bool/array/map/class). evaluate_binary_op turns that None into this bail with the expression's source span. This is a type error: both sides must be orderable and of a comparable kind (e.g. both numbers, both strings).","triggerScenarios":"Evaluating `a < b` where compare_values yields None: mixed numeric/string operands (`5 < \"3\"`), ordering bools, arrays, maps, or class instances, or comparing a number with null.","commonSituations":"Comparing a numeric LLM field against a string-typed value; comparing values read from a map with unknown/stored types; accidentally comparing a string variable that should have been cast to int; comparing optional/null values with numbers.","solutions":["Make both operands the same comparable type: cast `as int` / `as float` or compare string-to-string","Print both operands before the comparison to spot a type mismatch","If values come from LLM output, type the schema field numerically or parse before comparing","Handle null/optional values before applying `<`"],"exampleFix":"// before (.baml)\nif age < threshold_str { ... } // threshold_str: string\n// after (.baml)\nif age < threshold_str as int { ... }","handlingStrategy":"validation","validationCode":"// .baml — ensure same comparable types\nlet t = threshold_str as int;\nif value < t { ... }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Compare like with like: numbers with numbers, strings with strings","Type LLM output fields numerically in the schema when they will be compared","Never compare bools, arrays, maps, or class instances with `<`","Null-check optional values before ordering comparisons"],"tags":["baml","interpreter","comparison","type-error"],"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"}