{"record":{"id":"3181e3957eeb6809","repo":"BoundaryML/baml","slug":"could-not-unify-int-with","errorCode":null,"errorMessage":"Could not unify Int with {:?}","messagePattern":"Could not unify Int with (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-core/src/ir/ir_helpers/mod.rs","lineNumber":265,"sourceCode":"            }\n            BamlValueWithMeta::Int(i, meta)\n                if self.is_subtype(\n                    &TypeIR::Literal(LiteralValue::Int(i), Default::default()),\n                    &field_type,\n                ) =>\n            {\n                Ok(BamlValueWithMeta::Int(i, (meta, field_type)))\n            }\n            BamlValueWithMeta::Int(i, meta)\n                if self.is_subtype(\n                    &TypeIR::Primitive(TypeValue::Int, Default::default()),\n                    &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","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-core/src/ir/ir_helpers/mod.rs#L247-L283","documentation":"Same unification path as error 738 for integers: distribute_type_with_meta fails with 'Could not unify Int with {field_type:?}' when an Int value's literal/primitive type is not a subtype of the expected field type. The schema expected something other than an int at this position.","triggerScenarios":"Distributing a BamlValueWithMeta::Int into a field whose TypeIR is not int and not a matching int literal — e.g. an int value assigned to a string, float (if not subtype), or class field.","commonSituations":"Model returned a number where the schema declares a string or enum; changed a field's type in .baml without updating consumers; enum-typed fields receiving raw ints.","solutions":["Align the .baml field type with the actual int value (declare it int)","Convert the value (e.g. ToString) before distribution if the field is a string","Fix enum fields to map literals correctly or declare the field as int","Regenerate client code after type changes"],"exampleFix":"// before (.baml)\nclass A { name int }  // value: 5 (int) expected string\n// after\nclass A { name string }\n// or: class A { name int }","handlingStrategy":"try-catch","validationCode":"fn is_int_compatible(v: i64, t: &TypeIR) -> bool {\n  matches!(t, TypeIR::Primitive(TypeValue::Int, _))\n    || matches!(t, TypeIR::Literal(LiteralValue::Int(i), _) if *i == v)\n}","typeGuard":"fn as_int_field(v: &BamlValue, t: &TypeIR) -> Option<i64> {\n  match v {\n    BamlValue::Int(i) => Some(*i),\n    _ => None,\n  }\n}","tryCatchPattern":"match distribute_type(&value, &field_type) {\n  Ok(v) => v,\n  Err(e) if e.to_string().contains(\"Could not unify Int\") => {\n    // coerce or report: value is numeric but schema disagrees\n    return Err(e.context(\"schema expects non-int field for numeric value\"));\n  }\n  Err(e) => return Err(e),\n}","preventionTips":["Ensure enum/number fields declare int when the model emits numbers","Convert numeric strings to ints before distribution if the field is int","Keep .baml type definitions and downstream parsing in sync"],"tags":["baml","unification","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-14T11:17:12.474Z"}