{"record":{"id":"423fd3dfb71ea205","repo":"BoundaryML/baml","slug":"unsupported-types-for-operator-at-interpret","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":2381,"sourceCode":"            (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, _)) => {\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::Div => match (left_val.clone(), right_val.clone()) {\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {","sourceCodeStart":2363,"sourceCodeEnd":2399,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2363-L2399","documentation":"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.","triggerScenarios":"Subtracting strings, nulls, booleans, or arrays; a variable expected to be numeric actually holding a string from an LLM response or config.","commonSituations":"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.","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"],"exampleFix":"// before\nlet diff = input - 10;    // input is \"42\"\n// after\nlet diff = toInt(input) - 10;","handlingStrategy":"validation","validationCode":"if (typeof a !== 'number' || typeof b !== 'number') { throw new Error('subtraction requires numeric operands'); }","typeGuard":"function isNumeric(v) { return typeof v === 'number' && !Number.isNaN(v); }","tryCatchPattern":"try { result = a - b; } catch (e) { if (String(e).includes('unsupported types for -')) { /* convert to numbers and retry */ } else { throw e; } }","preventionTips":["Parse numeric strings before arithmetic","Null-check operands","Validate types of LLM/config-sourced values"],"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"}