BoundaryML/baml · error

unsupported types for >= operator at

Error message

unsupported types for >= operator at {:?}

What it means

The `>=` operator depends on compare_values returning Some(ordering); for operand pairs with no defined ordering (mismatched types or non-orderable types like bool/array/map/class) it returns None and this bail fires with the expression's source span. This is a compile-time-interpreted type error in the BAML expression.

Solutions

  1. Unify operand types with `as int` / `as float` casts (or compare string-to-string)
  2. Inspect both operands (print values/types) at the failing comparison
  3. Fix the schema/prompt so numeric values arrive as numbers, not strings
  4. Null-check optional values before the comparison

Example fix

// before (.baml)
if value >= min_str { ... } // min_str: string
// after (.baml)
if value >= min_str as int { ... }
Defensive patterns

Strategy: validation

Validate before calling

// .baml — cast and null-check before `>=`
let min = min_str as int;
if value >= min { ... }

Prevention

When it happens

Trigger: Evaluating `a >= b` with incompatible or unordered operands: number vs string, string vs number, bools, arrays, maps, class instances, or comparisons involving null.

Common situations: Range checks where the upper bound came from string config or LLM output; comparing a typed numeric field against an untyped map value; forgetting a cast after string parsing; comparing booleans with `>=`.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/72a71daa1219b8d4. Report an issue: GitHub.

Appendix: source

Thrown at engine/baml-compiler/src/thir/interpret.rs:2469

        BinaryOperator::LtEq => {
            let ord_opt = compare_values(&left_val.clone(), &right_val.clone())?;
            let less_eq = ord_opt
                .map(|ord| matches!(ord, std::cmp::Ordering::Less | std::cmp::Ordering::Equal))
                .ok_or_else(|| anyhow!("unsupported types for <= operator at {:?}", meta.0))?;
            BamlValueWithMeta::Bool(less_eq, meta.clone())
        }
        BinaryOperator::Gt => {
            let ord_opt = compare_values(&left_val.clone(), &right_val.clone())?;
            let greater = ord_opt
                .map(|ord| matches!(ord, std::cmp::Ordering::Greater))
                .ok_or_else(|| anyhow!("unsupported types for > operator at {:?}", meta.0))?;
            BamlValueWithMeta::Bool(greater, meta.clone())
        }
        BinaryOperator::GtEq => {
            let ord_opt = compare_values(&left_val.clone(), &right_val.clone())?;
            let greater_eq = ord_opt
                .map(|ord| matches!(ord, std::cmp::Ordering::Greater | std::cmp::Ordering::Equal))
                .ok_or_else(|| anyhow!("unsupported types for >= operator at {:?}", meta.0))?;
            BamlValueWithMeta::Bool(greater_eq, meta.clone())
        }

        // Logical operations
        BinaryOperator::And => match left_val.clone() {
            BamlValueWithMeta::Bool(false, _) => BamlValueWithMeta::Bool(false, meta.clone()),
            BamlValueWithMeta::Bool(true, _) => match right_val.clone() {
                BamlValueWithMeta::Bool(b, _) => BamlValueWithMeta::Bool(b, meta.clone()),
                _ => bail!("right operand of && must be bool at {:?}", meta.0),
            },
            _ => bail!("left operand of && must be bool at {:?}", meta.0),
        },
        BinaryOperator::Or => match left_val.clone() {
            BamlValueWithMeta::Bool(true, _) => BamlValueWithMeta::Bool(true, meta.clone()),
            BamlValueWithMeta::Bool(false, _) => match right_val.clone() {
                BamlValueWithMeta::Bool(b, _) => BamlValueWithMeta::Bool(b, meta.clone()),
                _ => bail!("right operand of || must be bool at {:?}", meta.0),
            },

View on GitHub (pinned to bd85ce9dee)