{"record":{"id":"46fa5527770a7690","repo":"BoundaryML/baml","slug":"could-not-unify-float-with","errorCode":null,"errorMessage":"Could not unify Float with {:?}","messagePattern":"Could not unify Float with (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-core/src/ir/ir_helpers/mod.rs","lineNumber":277,"sourceCode":"                    &field_type,\n                ) =>\n            {\n                Ok(BamlValueWithMeta::Int(i, (meta, field_type)))\n            }\n            BamlValueWithMeta::Int(_i, _meta) => {\n                anyhow::bail!(\"Could not unify Int with {:?}\", field_type)\n            }\n\n            BamlValueWithMeta::Float(f, meta)\n                if self.is_subtype(\n                    &TypeIR::Primitive(TypeValue::Float, Default::default()),\n                    &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) => {","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-core/src/ir/ir_helpers/mod.rs#L259-L295","documentation":"In BAML's IR type-distribution pass, a Float value could not be matched against the declared field type: `is_subtype(float, field_type)` failed, so `distribute_type_with_meta` bails instead of annotating the value with the type. This happens when a runtime float is checked against a type that is not `float` (nor an alias/union member resolving to float).","triggerScenarios":"Calling IRHelper::distribute_type (directly or via distribute_type_with_meta) with a BamlValueWithMeta::Float while the expected TypeIR is e.g. `int`, `string`, a class, or an unrelated enum/alias; typically during function-argument checking or testfile value typing where the declared parameter type doesn't accept floats.","commonSituations":"Declaring a BAML function parameter as `int` or `string` but the client sends 1.5; a type alias changed from float to int; JSON payloads (always float-like for decimals) being validated against int-typed fields.","solutions":["Change the BAML function/field type to `float` (or `int | float`) so the value's type is accepted","Coerce the value to the expected type on the caller side (e.g. round/cast 1.5 to int before calling the function)","If the value should accept both, make the field optional or a union like `float | int` in the .baml schema","Check which parameter/field the error mentions and fix the client's argument payload to match the .baml definition"],"exampleFix":"// before (.baml)\nfunction GetScore(rating: int) -> float { ... }\n// caller sends rating: 4.5\n\n// after (.baml)\nfunction GetScore(rating: float) -> float { ... }","handlingStrategy":"validation","validationCode":"function validateFloatMatchesSchema(value: number, declaredType: string): boolean {\n  return declaredType === 'float' || declaredType === 'float | int' || declaredType === 'int | float';\n}\n// call before invoking: if (!validateFloatMatchesSchema(v, paramType)) throw new Error('fix .baml type or coerce value');","typeGuard":"const isFloat = (v: unknown): v is number => typeof v === 'number' && !Number.isInteger(v);","tryCatchPattern":null,"preventionTips":["Keep .baml numeric types aligned with what your client actually sends","Prefer `float` for decimal JSON values; JSON ints and floats are easy to confuse","Regenerate clients after any signature change","Add an argument-shape test per 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"}