BoundaryML/baml · error
Expected a boolean
Error message
Expected a boolean
What it means
resolve_bool resolves an UnresolvedValue at runtime and requires the result to be ResolvedValue::Bool; any other resolved variant (or a resolution failure such as an unset env var) produces this error. It enforces that the field truly evaluates to a boolean rather than coercing truthy values.
Source
Thrown at engine/baml-lib/baml-types/src/value_expr.rs:548
Self::Map(..) => anyhow::bail!("Expected a string, not a map"),
Self::Null(..) => anyhow::bail!("Expected a string, not null"),
Self::ClassConstructor(..) => {
anyhow::bail!("Expected a string, not a class constructor")
}
}
}
pub fn resolve_string(&self, ctx: &impl GetEnvVar) -> Result<String> {
match self.resolve(ctx) {
Ok(ResolvedValue::String(s, ..)) => Ok(s),
_ => Err(anyhow::anyhow!("Expected a string")),
}
}
pub fn resolve_bool(&self, ctx: &impl GetEnvVar) -> Result<bool> {
match self.resolve(ctx) {
Ok(ResolvedValue::Bool(b, ..)) => Ok(b),
_ => Err(anyhow::anyhow!("Expected a boolean")),
}
}
pub fn resolve_array(&self, ctx: &impl GetEnvVar) -> Result<Vec<ResolvedValue>> {
match self.resolve(ctx) {
Ok(ResolvedValue::Array(a, ..)) => Ok(a),
_ => Err(anyhow::anyhow!("Expected an array")),
}
}
pub fn resolve_map(&self, ctx: &impl GetEnvVar) -> Result<IndexMap<String, ResolvedValue>> {
match self.resolve(ctx) {
Ok(ResolvedValue::Map(m, ..)) => Ok(m.into_iter().map(|(k, (_, v))| (k, v)).collect()),
_ => Err(anyhow::anyhow!("Expected a map")),
}
}
pub fn resolve_numeric(&self, ctx: &impl GetEnvVar) -> Result<String> {View on GitHub (pinned to bd85ce9dee)
Solutions
- Author the value as a bare boolean literal (true/false) in .baml, not "true" or 1
- If driven by an env var, ensure its value is exactly true or false, or convert in code after resolve_string
- Use resolve_string and parse manually when the source cannot be changed to a boolean type
Example fix
// before (baml)
options {
stream "true"
}
// after (baml)
options {
stream true
} Defensive patterns
Strategy: validation
Validate before calling
// Rust
match value.resolve(&ctx) {
Ok(ResolvedValue::Bool(_)) => {},
Ok(ResolvedValue::String(s, _)) => {
anyhow::ensure!(s == "true" || s == "false", "field must be boolean, got string {s}");
}
_ => anyhow::bail!("field must resolve to a boolean"),
} Type guard
fn resolves_to_bool(v: &UnresolvedValue<()>, ctx: &EvaluationContext) -> bool {
matches!(v.resolve(ctx), Ok(ResolvedValue::Bool(..)))
} Try / catch
// Rust
let b = value.resolve_bool(&ctx)
.with_context(|| format!("field '{name}' must be true/false (unquoted), not a string or number"))?; Prevention
- Write booleans unquoted in .baml (true/false)
- For env-driven flags, ensure env values are exactly true/false or parse them yourself
- Never rely on truthy coercion of strings or numbers
When it happens
Trigger: Calling resolve_bool(ctx) where resolve(ctx) returns a non-Bool ResolvedValue — e.g. the BAML field is the string "true", a number 1, or an env::VAR whose value is not a boolean literal.
Common situations: Setting boolean options via env vars (env::ENABLE_X) where the env value is "1"/"yes" instead of BAML boolean literals true/false, or quoting booleans as strings by mistake.
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
- Could not unify Float with {:?}
- Could not unify Bool with {:?}
- Unification error
- Expected a string, not an array
- Expected a string, not a bool
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/d513a0c735bd8905.
Report an issue: GitHub.