BoundaryML/baml · error
unsupported types for - operator at
Error message
unsupported types for - operator at {:?} What it means
THIR interpreter runtime error: the binary `-` operator was applied to operand types with no defined subtraction — only int/int, float/float, and mixed numeric pairs are supported. Any other combination (string, bool, null, list, map on either side) reaches this bail with the expression's source metadata attached.
Solutions
- Convert operands to numbers explicitly before subtracting
- Validate/parse LLM or config outputs into Int/Float types first
- Check for null and handle missing values before arithmetic
Example fix
// before let diff = input - 10; // input is "42" // after let diff = toInt(input) - 10;
Defensive patterns
Strategy: validation
Validate before calling
if (typeof a !== 'number' || typeof b !== 'number') { throw new Error('subtraction requires numeric operands'); } Type guard
function isNumeric(v) { return typeof v === 'number' && !Number.isNaN(v); } Try / catch
try { result = a - b; } catch (e) { if (String(e).includes('unsupported types for -')) { /* convert to numbers and retry */ } else { throw e; } } Prevention
- Parse numeric strings before arithmetic
- Null-check operands
- Validate types of LLM/config-sourced values
When it happens
Trigger: Subtracting strings, nulls, booleans, or arrays; a variable expected to be numeric actually holding a string from an LLM response or config.
Common situations: Numeric strings from parsed LLM output used directly in arithmetic; null from a missing optional value; copying JS code that relies on implicit string-to-number coercion.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- unsupported types for + operator at
- unsupported types for * operator at
- for loop requires iterable (list)
- unsupported types for += operator
- division by zero at
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/423fd3dfb71ea205.
Report an issue: GitHub.
Appendix: source
Thrown at engine/baml-compiler/src/thir/interpret.rs:2381
(BamlValueWithMeta::String(a, _), BamlValueWithMeta::String(b, _)) => {
BamlValueWithMeta::String(format!("{a}{b}"), meta.clone())
}
_ => bail!("unsupported types for + operator at {:?}", meta.0),
},
BinaryOperator::Sub => match (left_val.clone(), right_val.clone()) {
(BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {
BamlValueWithMeta::Int(a - b, meta.clone())
}
(BamlValueWithMeta::Float(a, _), BamlValueWithMeta::Float(b, _)) => {
BamlValueWithMeta::Float(a - b, meta.clone())
}
(BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Float(b, _)) => {
BamlValueWithMeta::Float((a as f64) - b, meta.clone())
}
(BamlValueWithMeta::Float(a, _), BamlValueWithMeta::Int(b, _)) => {
BamlValueWithMeta::Float(a - (b as f64), meta.clone())
}
_ => bail!("unsupported types for - operator at {:?}", meta.0),
},
BinaryOperator::Mul => match (left_val.clone(), right_val.clone()) {
(BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {
BamlValueWithMeta::Int(a * b, meta.clone())
}
(BamlValueWithMeta::Float(a, _), BamlValueWithMeta::Float(b, _)) => {
BamlValueWithMeta::Float(a * b, meta.clone())
}
(BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Float(b, _)) => {
BamlValueWithMeta::Float((a as f64) * b, meta.clone())
}
(BamlValueWithMeta::Float(a, _), BamlValueWithMeta::Int(b, _)) => {
BamlValueWithMeta::Float(a * (b as f64), meta.clone())
}
_ => bail!("unsupported types for * operator at {:?}", meta.0),
},
BinaryOperator::Div => match (left_val.clone(), right_val.clone()) {
(BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {View on GitHub (pinned to bd85ce9dee)