{"record":{"id":"ac29d28defceba26","repo":"BoundaryML/baml","slug":"could-not-unify-bool-with","errorCode":null,"errorMessage":"Could not unify Bool with {:?}","messagePattern":"Could not unify Bool with (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-core/src/ir/ir_helpers/mod.rs","lineNumber":289,"sourceCode":"                    &field_type,\n                ) =>\n            {\n                Ok(BamlValueWithMeta::Float(f, (meta, field_type)))\n            }\n            BamlValueWithMeta::Float(_, _) => {\n                anyhow::bail!(\"Could not unify Float with {:?}\", field_type)\n            }\n\n            BamlValueWithMeta::Bool(b, meta) => {\n                let literal_type = TypeIR::Literal(LiteralValue::Bool(b), Default::default());\n                let primitive_type = TypeIR::Primitive(TypeValue::Bool, Default::default());\n\n                if self.is_subtype(&literal_type, &field_type)\n                    || self.is_subtype(&primitive_type, &field_type)\n                {\n                    Ok(BamlValueWithMeta::Bool(b, (meta, field_type)))\n                } else {\n                    anyhow::bail!(\"Could not unify Bool with {:?}\", field_type)\n                }\n            }\n\n            BamlValueWithMeta::Null(meta) => Ok(BamlValueWithMeta::Null((meta, field_type))),\n\n            BamlValueWithMeta::Map(pairs, meta) => {\n                let (annotation_key_type, annotation_value_type) = map_types(self, &field_type)\n                    .ok_or(anyhow::anyhow!(\"Could not unify map with {field_type:?}\"))?;\n\n                let mapped_fields: BamlMap<String, BamlValueWithMeta<(T, TypeIR)>> = pairs\n                    .into_iter()\n                    .map(|(key, val)| {\n                        let sub_value =\n                            self.distribute_type_with_meta(val, annotation_value_type.clone())?;\n\n                        Ok((key, sub_value))\n                    })\n                    .collect::<anyhow::Result<BamlMap<String, BamlValueWithMeta<(T, TypeIR)>>>>()?;","sourceCodeStart":271,"sourceCodeEnd":307,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-core/src/ir/ir_helpers/mod.rs#L271-L307","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before (.baml)\nfunction Flag(enabled: string) -> bool { ... }\n// caller sends enabled: true\n\n// after (.baml)\nfunction Flag(enabled: bool) -> bool { ... }","handlingStrategy":"validation","validationCode":"function validateBoolMatchesSchema(value: unknown, declaredType: string): boolean {\n  return typeof value === 'boolean' && (declaredType === 'bool' || declaredType.includes('bool'));\n}","typeGuard":"const isBool = (v: unknown): v is boolean => typeof v === 'boolean';","tryCatchPattern":null,"preventionTips":["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"],"tags":["rust","type-system","baml","type-mismatch"],"backgroundTag":"type-mismatch","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}