{"record":{"id":"6a9f0d46d387720b","repo":"BoundaryML/baml","slug":"right-operand-of-must-be-bool-at-interpret","errorCode":null,"errorMessage":"right operand of || must be bool at {:?}","messagePattern":"right operand of \\|\\| must be bool at (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-compiler/src/thir/interpret.rs","lineNumber":2486,"sourceCode":"                .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()) {\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()) {","sourceCodeStart":2468,"sourceCodeEnd":2504,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-compiler/src/thir/interpret.rs#L2468-L2504","documentation":"The `||` operator short-circuits: when the left operand evaluates to `false`, the right operand must be a Bool for the result to be typed correctly. evaluate_binary_op bails with this message when the right operand of `||` is a non-bool BamlValue. BAML has no truthy coercion.","triggerScenarios":"Evaluating `a || b` where `a` is false and `b` is a non-boolean value, e.g. `false ?? \"\"` rewritten as `false || \"default\"`, or `isMissing || fallbackValue` where fallbackValue is a string.","commonSituations":"Using `||` as a defaulting operator (JS-style) instead of proper null coalescing; a fallback variable typed as string/int being OR-ed with a boolean flag.","solutions":["Make the right operand a boolean expression: `isMissing || (count == 0)`.","Replace defaulting logic with an if/else expression: `if (isMissing) { true } else { fallback }` is invalid — instead compare explicitly.","Check the schema type of the right operand; if non-bool, restructure the condition."],"exampleFix":"// before (BAML)\nlet useCache = disableCache || envValue;\n// after\nlet useCache = disableCache || (envValue == \"1\");","handlingStrategy":"type-guard","validationCode":"// ensure right operand of || is bool\nif (typeof rightOperand !== 'boolean') throw new Error('right 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('right operand of || must be bool')) {\n    result = evaluate(fixOrOperands(expr));\n  } else throw e;\n}","preventionTips":["Do not use `||` as a defaulting operator for non-bool values","Use explicit if/else expressions for value fallbacks","Test each boolean expression with representative non-bool inputs"],"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"}