BoundaryML/baml · error

unsupported types for + operator at

Error message

unsupported types for + operator at {:?}

What it means

The `+` operator in the BAML interpreter supports only specific operand combinations: Int+Int, Float+Float, Int/Float mixed, and String+String concatenation. Any other pair (bool, null, list, class, string+number, etc.) reaches the catch-all bail.

Solutions

  1. Convert operands to matching types explicitly (e.g. string-conversion function for numbers before concatenation)
  2. Add both operands as Int or Float for arithmetic
  3. For lists, use push or list operations rather than `+`
  4. Guard null/possibly-missing values before the operation

Example fix

// before
let msg = "count: " + 5;
// after
let msg = "count: " + toString(5);
Defensive patterns

Strategy: validation

Validate before calling

function canAdd(a, b) {
  const num = v => typeof v === 'number';
  return (num(a) && num(b)) || (typeof a === 'string' && typeof b === 'string');
}

Type guard

function isAddable(a, b) { const num = v => typeof v === 'number'; return (num(a) && num(b)) || (typeof a === 'string' && typeof b === 'string'); }

Try / catch

try { result = a + b; } catch (e) { if (String(e).includes('unsupported types for +')) { /* coerce types explicitly and retry */ } else { throw e; } }

Prevention

When it happens

Trigger: Adding incompatible values: `"count: " + 5` (string + int), `null + 1`, adding lists, adding booleans, or adding a class instance.

Common situations: JS-style string coercion of numbers (`"a" + 1`) which BAML does not perform; null from an unevaluated or failed expression; concatenating list values instead of a loop/explicit join.

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


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

Appendix: source

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

    Ok(match operator {
        // Arithmetic operations
        BinaryOperator::Add => 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())
            }
            (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, _)) => {

View on GitHub (pinned to bd85ce9dee)