{"record":{"id":"85d20c80cb689196","repo":"BoundaryML/baml","slug":"unsupported-types-for-operator-at-85d20c","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":2462,"sourceCode":"        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())?;\n            let greater_eq = ord_opt\n                .map(|ord| matches!(ord, std::cmp::Ordering::Greater | std::cmp::Ordering::Equal))\n                .ok_or_else(|| anyhow!(\"unsupported types for >= operator at {:?}\", meta.0))?;\n            BamlValueWithMeta::Bool(greater_eq, meta.clone())\n        }\n\n        // Logical operations\n        BinaryOperator::And => match left_val.clone() {\n            BamlValueWithMeta::Bool(false, _) => BamlValueWithMeta::Bool(false, meta.clone()),\n            BamlValueWithMeta::Bool(true, _) => match right_val.clone() {\n                BamlValueWithMeta::Bool(b, _) => BamlValueWithMeta::Bool(b, meta.clone()),\n                _ => bail!(\"right operand of && must be bool at {:?}\", meta.0),\n            },\n            _ => bail!(\"left operand of && must be bool at {:?}\", meta.0),","sourceCodeStart":2444,"sourceCodeEnd":2480,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2444-L2480","documentation":"The `>` operator uses compare_values, which returns None for operand pairs with no defined ordering (different types or unordered types). evaluate_binary_op converts None into this bail, reporting the source span of the expression. Only mutually comparable, orderable values (numbers with numbers, strings with strings) are valid.","triggerScenarios":"Evaluating `a > b` where the operands are of different types (e.g. `\"10\" > 5`) or of non-orderable types (bool, array, map, class instance, null).","commonSituations":"Comparing LLM-returned strings against numeric literals; comparing values pulled from untyped containers; a numeric variable accidentally holding a string due to a schema type of string; comparing booleans with `>`.","solutions":["Cast both sides to a common numeric type (`as int` / `as float`) or compare strings with strings","Print both operands before the check to identify the type mismatch","Correct the field type in the schema/prompt so LLM output is numeric when needed","Handle null/optional values explicitly before `>`"],"exampleFix":"// before (.baml)\nif count > limit_str { ... } // limit_str: string\n// after (.baml)\nif count > limit_str as int { ... }","handlingStrategy":"validation","validationCode":"// .baml — unify types before `>`\nlet lim = limit_str as int;\nif count > lim { ... }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Cast operands to a common numeric type before `>` when sources differ","Avoid storing numbers as strings in maps/config used for comparisons","Declare prompt/schema output fields as numbers when used in ordering checks","Reject null/missing values explicitly before 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"}