BoundaryML/baml · error
right operand of || must be bool at
Error message
right operand of || must be bool at {:?} What it means
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.
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.
Example fix
// before (BAML) let useCache = disableCache || envValue; // after let useCache = disableCache || (envValue == "1");
Defensive patterns
Strategy: type-guard
Validate before calling
// ensure right operand of || is bool
if (typeof rightOperand !== 'boolean') throw new Error('right operand of || must be bool'); Type guard
const isBool = (v) => typeof v === 'boolean';
Try / catch
try {
result = evaluate(expr);
} catch (e) {
if (String(e).includes('right operand of || must be bool')) {
result = evaluate(fixOrOperands(expr));
} else throw e;
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- left operand of && must be bool at
- left operand of || must be bool at
- right operand of && must be bool at
- array assignment on non-list value at
- bitwise ^= requires integer operands
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/6a9f0d46d387720b.
Report an issue: GitHub.
Appendix: source
Thrown at engine/baml-compiler/src/thir/interpret.rs:2486
.map(|ord| matches!(ord, std::cmp::Ordering::Greater | std::cmp::Ordering::Equal))
.ok_or_else(|| anyhow!("unsupported types for >= operator at {:?}", meta.0))?;
BamlValueWithMeta::Bool(greater_eq, meta.clone())
}
// Logical operations
BinaryOperator::And => match left_val.clone() {
BamlValueWithMeta::Bool(false, _) => BamlValueWithMeta::Bool(false, meta.clone()),
BamlValueWithMeta::Bool(true, _) => match right_val.clone() {
BamlValueWithMeta::Bool(b, _) => BamlValueWithMeta::Bool(b, meta.clone()),
_ => bail!("right operand of && must be bool at {:?}", meta.0),
},
_ => bail!("left operand of && must be bool at {:?}", meta.0),
},
BinaryOperator::Or => match left_val.clone() {
BamlValueWithMeta::Bool(true, _) => BamlValueWithMeta::Bool(true, meta.clone()),
BamlValueWithMeta::Bool(false, _) => match right_val.clone() {
BamlValueWithMeta::Bool(b, _) => BamlValueWithMeta::Bool(b, meta.clone()),
_ => bail!("right operand of || must be bool at {:?}", meta.0),
},
_ => bail!("left operand of || must be bool at {:?}", meta.0),
},
// Bitwise operations (integer only)
BinaryOperator::BitAnd => match (left_val.clone(), right_val.clone()) {
(BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {
BamlValueWithMeta::Int(a & b, meta.clone())
}
_ => bail!("bitwise & requires integer operands at {:?}", meta.0),
},
BinaryOperator::BitOr => match (left_val.clone(), right_val.clone()) {
(BamlValueWithMeta::Int(a, _), BamlValueWithMeta::Int(b, _)) => {
BamlValueWithMeta::Int(a | b, meta.clone())
}
_ => bail!("bitwise | requires integer operands at {:?}", meta.0),
},
BinaryOperator::BitXor => match (left_val.clone(), right_val.clone()) {View on GitHub (pinned to bd85ce9dee)