{"record":{"id":"e89158a25cac52b7","repo":"BoundaryML/baml","slug":"unsupported-types-for-operator-at","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":2366,"sourceCode":"    Ok(match operator {\n        // Arithmetic operations\n        BinaryOperator::Add => match (left_val.clone(), right_val.clone()) {\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {\n                BamlValueWithMeta::Int(a + b, meta.clone())\n            }\n            (BamlValueWithMeta::Float(a, _), BamlValueWithMeta::Float(b, _)) => {\n                BamlValueWithMeta::Float(a + b, meta.clone())\n            }\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Float(b, _)) => {\n                BamlValueWithMeta::Float(a as f64 + b, meta.clone())\n            }\n            (BamlValueWithMeta::Float(a, _), BamlValueWithMeta::Int(b, _)) => {\n                BamlValueWithMeta::Float(a + (b as f64), meta.clone())\n            }\n            (BamlValueWithMeta::String(a, _), BamlValueWithMeta::String(b, _)) => {\n                BamlValueWithMeta::String(format!(\"{a}{b}\"), meta.clone())\n            }\n            _ => bail!(\"unsupported types for + operator at {:?}\", meta.0),\n        },\n        BinaryOperator::Sub => match (left_val.clone(), right_val.clone()) {\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {\n                BamlValueWithMeta::Int(a - b, meta.clone())\n            }\n            (BamlValueWithMeta::Float(a, _), BamlValueWithMeta::Float(b, _)) => {\n                BamlValueWithMeta::Float(a - b, meta.clone())\n            }\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Float(b, _)) => {\n                BamlValueWithMeta::Float((a as f64) - b, meta.clone())\n            }\n            (BamlValueWithMeta::Float(a, _), BamlValueWithMeta::Int(b, _)) => {\n                BamlValueWithMeta::Float(a - (b as f64), meta.clone())\n            }\n            _ => bail!(\"unsupported types for - operator at {:?}\", meta.0),\n        },\n        BinaryOperator::Mul => match (left_val.clone(), right_val.clone()) {\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {","sourceCodeStart":2348,"sourceCodeEnd":2384,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2348-L2384","documentation":"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.","triggerScenarios":"Adding incompatible values: `\"count: \" + 5` (string + int), `null + 1`, adding lists, adding booleans, or adding a class instance.","commonSituations":"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.","solutions":["Convert operands to matching types explicitly (e.g. string-conversion function for numbers before concatenation)","Add both operands as Int or Float for arithmetic","For lists, use push or list operations rather than `+`","Guard null/possibly-missing values before the operation"],"exampleFix":"// before\nlet msg = \"count: \" + 5;\n// after\nlet msg = \"count: \" + toString(5);","handlingStrategy":"validation","validationCode":"function canAdd(a, b) {\n  const num = v => typeof v === 'number';\n  return (num(a) && num(b)) || (typeof a === 'string' && typeof b === 'string');\n}","typeGuard":"function isAddable(a, b) { const num = v => typeof v === 'number'; return (num(a) && num(b)) || (typeof a === 'string' && typeof b === 'string'); }","tryCatchPattern":"try { result = a + b; } catch (e) { if (String(e).includes('unsupported types for +')) { /* coerce types explicitly and retry */ } else { throw e; } }","preventionTips":["Don't rely on implicit string/number coercion; convert explicitly","Null-check operands before arithmetic","Validate LLM output types before using in expressions"],"tags":["runtime","operators","type-error","interpreter"],"backgroundTag":"unsupported-operation","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"}