{"record":{"id":"6744267565d10987","repo":"BoundaryML/baml","slug":"left-operand-of-must-be-bool-at","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":2480,"sourceCode":"                .ok_or_else(|| anyhow!(\"unsupported types for > operator at {:?}\", meta.0))?;\n            BamlValueWithMeta::Bool(greater, meta.clone())\n        }\n        BinaryOperator::GtEq => {\n            let ord_opt = compare_values(&left_val.clone(), &right_val.clone())?;\n            let greater_eq = ord_opt\n                .map(|ord| matches!(ord, std::cmp::Ordering::Greater | std::cmp::Ordering::Equal))\n                .ok_or_else(|| anyhow!(\"unsupported types for >= operator at {:?}\", meta.0))?;\n            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()) {","sourceCodeStart":2462,"sourceCodeEnd":2498,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2462-L2498","documentation":"In evaluate_binary_op, the `&&` operator requires both operands to be BamlValueWithMeta::Bool. If the left operand is anything other than Bool (and did not short-circuit as false), the interpreter bails with this message. BAML does not coerce values to booleans.","triggerScenarios":"Evaluating `a && b` where `a` is a non-bool value: e.g. `items && items.length > 0`, `42 && flag`, `null && x`. Any string, int, null, list, or map used as the left operand of `&&`.","commonSituations":"JavaScript-style truthiness idioms copied into BAML; a variable that was expected to be bool but is actually an optional/nullable check result; refactoring where a comparison was accidentally dropped.","solutions":["Add an explicit boolean expression as the left operand: `items != null && items.length > 0`.","Verify the left operand's type in the schema; if it is nullable, test `x != null` explicitly.","If short-circuiting for side effects/defaulting, use an if/else expression instead of `&&`."],"exampleFix":"// before (BAML)\nlet ok = items && items.length > 0;\n// after\nlet ok = items != null && items.length > 0;","handlingStrategy":"type-guard","validationCode":"// validate left operand before &&\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":["Convert JS-style `a && a.b` guards to explicit null checks","Declare flag variables as bool in the BAML schema","Review expressions where operands come from untyped LLM output"],"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"}