BoundaryML/baml · error
unsupported types for < operator at
Error message
unsupported types for < operator at {:?} What it means
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).
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 `<`
Example fix
// before (.baml)
if age < threshold_str { ... } // threshold_str: string
// after (.baml)
if age < threshold_str as int { ... } Defensive patterns
Strategy: validation
Validate before calling
// .baml — ensure same comparable types
let t = threshold_str as int;
if value < t { ... } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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
- unsupported types for <= operator at
- unsupported types for >= operator at
- unsupported types for > operator at
- modulo by zero at
- unsupported types for % operator at
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/cc4d19a0c2ab6ad1.
Report an issue: GitHub.
Appendix: source
Thrown at engine/baml-compiler/src/thir/interpret.rs:2448
BamlValueWithMeta::Int(a % b, meta.clone())
}
_ => bail!("unsupported types for % operator at {:?}", meta.0),
},
// Comparison operations
BinaryOperator::Eq => {
let equal = values_equal(&left_val.clone(), &right_val.clone());
BamlValueWithMeta::Bool(equal, meta.clone())
}
BinaryOperator::Neq => {
let not_equal = !values_equal(&left_val.clone(), &right_val.clone());
BamlValueWithMeta::Bool(not_equal, meta.clone())
}
BinaryOperator::Lt => {
let ord_opt = compare_values(&left_val.clone(), &right_val.clone())?;
let less = ord_opt
.map(|ord| matches!(ord, std::cmp::Ordering::Less))
.ok_or_else(|| anyhow!("unsupported types for < operator at {:?}", meta.0))?;
BamlValueWithMeta::Bool(less, meta.clone())
}
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())?;View on GitHub (pinned to bd85ce9dee)