BoundaryML/baml · error · anyhow::Error
Could not unify Bool with {:?}
Error message
Could not unify Bool with {:?} What it means
BAML's IR type-distribution pass encountered a Bool value whose expected TypeIR is neither the `bool` primitive nor a matching boolean literal, so `distribute_type_with_meta` refuses to attach the type and bails. It enforces that runtime boolean values line up with the declared schema type.
Source
Thrown at engine/baml-lib/baml-core/src/ir/ir_helpers/mod.rs:289
&field_type,
) =>
{
Ok(BamlValueWithMeta::Float(f, (meta, field_type)))
}
BamlValueWithMeta::Float(_, _) => {
anyhow::bail!("Could not unify Float with {:?}", field_type)
}
BamlValueWithMeta::Bool(b, meta) => {
let literal_type = TypeIR::Literal(LiteralValue::Bool(b), Default::default());
let primitive_type = TypeIR::Primitive(TypeValue::Bool, Default::default());
if self.is_subtype(&literal_type, &field_type)
|| self.is_subtype(&primitive_type, &field_type)
{
Ok(BamlValueWithMeta::Bool(b, (meta, field_type)))
} else {
anyhow::bail!("Could not unify Bool with {:?}", field_type)
}
}
BamlValueWithMeta::Null(meta) => Ok(BamlValueWithMeta::Null((meta, field_type))),
BamlValueWithMeta::Map(pairs, meta) => {
let (annotation_key_type, annotation_value_type) = map_types(self, &field_type)
.ok_or(anyhow::anyhow!("Could not unify map with {field_type:?}"))?;
let mapped_fields: BamlMap<String, BamlValueWithMeta<(T, TypeIR)>> = pairs
.into_iter()
.map(|(key, val)| {
let sub_value =
self.distribute_type_with_meta(val, annotation_value_type.clone())?;
Ok((key, sub_value))
})
.collect::<anyhow::Result<BamlMap<String, BamlValueWithMeta<(T, TypeIR)>>>>()?;View on GitHub (pinned to bd85ce9dee)
Solutions
- Update the .baml declaration to type the field/parameter as `bool`
- Convert the value before calling (e.g. stringify the bool if the schema expects string)
- If literals are involved, ensure the literal type in the schema actually matches the runtime boolean value
- Log the `field_type` from the error to identify which declared type rejected the value and fix the caller payload
Example fix
// before (.baml)
function Flag(enabled: string) -> bool { ... }
// caller sends enabled: true
// after (.baml)
function Flag(enabled: bool) -> bool { ... } Defensive patterns
Strategy: validation
Validate before calling
function validateBoolMatchesSchema(value: unknown, declaredType: string): boolean {
return typeof value === 'boolean' && (declaredType === 'bool' || declaredType.includes('bool'));
} Type guard
const isBool = (v: unknown): v is boolean => typeof v === 'boolean';
Prevention
- Never stringify booleans for bool-typed BAML parameters
- Check `?` optionality before omitting arguments
- Regenerate SDKs after .baml edits
- Unit-test argument maps against the function signature
When it happens
Trigger: Running distribute_type/distribute_type_with_meta on BamlValueWithMeta::Bool when field_type is `string`, `int`, a literal of another value, or any non-bool type — e.g. validating function arguments or typed values against the .baml schema.
Common situations: Passing `true`/`false` where a string like "true" is expected (or vice versa); schema drift after renaming a field's type in the .baml file; client SDK sending JSON booleans for string-typed params.
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 map with {field_type:?}
- Could not infer child type
- Could not unify Media with {:?}
- Could not unify Enum {} with {:?}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/ac29d28defceba26.
Report an issue: GitHub.