{"record":{"id":"b02460d3b226ef2b","repo":"BoundaryML/baml","slug":"left-operand-of-must-be-bool-at-interpret","errorCode":null,"errorMessage":"left operand of || must be bool at {:?}","messagePattern":"left operand of \\|\\| must be bool at (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2488,"sourceCode":"            BamlValueWithMeta::Bool(greater_eq, meta.clone())\n        }\n\n        // Logical operations\n        BinaryOperator::And => match left_val.clone() {\n            BamlValueWithMeta::Bool(false, _) => BamlValueWithMeta::Bool(false, meta.clone()),\n            BamlValueWithMeta::Bool(true, _) => match right_val.clone() {\n                BamlValueWithMeta::Bool(b, _) => BamlValueWithMeta::Bool(b, meta.clone()),\n                _ => bail!(\"right operand of && must be bool at {:?}\", meta.0),\n            },\n            _ => bail!(\"left operand of && must be bool at {:?}\", meta.0),\n        },\n        BinaryOperator::Or => match left_val.clone() {\n            BamlValueWithMeta::Bool(true, _) => BamlValueWithMeta::Bool(true, meta.clone()),\n            BamlValueWithMeta::Bool(false, _) => match right_val.clone() {\n                BamlValueWithMeta::Bool(b, _) => BamlValueWithMeta::Bool(b, meta.clone()),\n                _ => bail!(\"right operand of || must be bool at {:?}\", meta.0),\n            },\n            _ => bail!(\"left operand of || must be bool at {:?}\", meta.0),\n        },\n\n        // Bitwise operations (integer only)\n        BinaryOperator::BitAnd => match (left_val.clone(), right_val.clone()) {\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {\n                BamlValueWithMeta::Int(a & b, meta.clone())\n            }\n            _ => bail!(\"bitwise & requires integer operands at {:?}\", meta.0),\n        },\n        BinaryOperator::BitOr => match (left_val.clone(), right_val.clone()) {\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {\n                BamlValueWithMeta::Int(a | b, meta.clone())\n            }\n            _ => bail!(\"bitwise | requires integer operands at {:?}\", meta.0),\n        },\n        BinaryOperator::BitXor => match (left_val.clone(), right_val.clone()) {\n            (BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {\n                BamlValueWithMeta::Int(a ^ b, meta.clone())","sourceCodeStart":2470,"sourceCodeEnd":2506,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2470-L2506","documentation":"The `||` operator in BAML's interpreter requires both operands to be Bool. If the left operand is not BamlValueWithMeta::Bool (it didn't short-circuit as true), evaluate_binary_op bails with this message. No truthiness coercion is performed.","triggerScenarios":"Evaluating `a || b` where `a` is a string, int, null, list, or map — e.g. `configValue || defaultFlag`, `0 || true`, `null || cond`.","commonSituations":"JS/Python truthy-or-default patterns ported to BAML; variables expected to hold comparison results but holding raw config/LLM output values.","solutions":["Add an explicit comparison to make the left operand bool: `(configValue != null) || defaultFlag`.","Inspect the left operand's type; if it comes from LLM output or config, coerce with an explicit equality or null check first.","Use if/else expressions for value selection instead of `||`."],"exampleFix":"// before (BAML)\nlet enabled = userSetting || true;\n// after\nlet enabled = (userSetting != null) || true;","handlingStrategy":"type-guard","validationCode":"// ensure left operand of || is bool\nif (typeof leftOperand !== 'boolean') throw new Error('left operand of || must be bool');","typeGuard":"const isBool = (v) => typeof v === 'boolean';","tryCatchPattern":"try {\n  result = evaluate(expr);\n} catch (e) {\n  if (String(e).includes('left operand of || must be bool')) {\n    result = evaluate(expr.replace(leftSrc, `(${leftSrc} != null)`));\n  } else throw e;\n}","preventionTips":["Ensure condition sources (LLM fields, config) are compared before use in ||","Adopt a lint rule forbidding bare identifiers as logical-operator operands","Document that BAML has no truthiness coercion"],"tags":["baml","type-mismatch","interpreter","logical-operator"],"backgroundTag":"type-mismatch","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"}