{"record":{"id":"4514f513e47b9fa3","repo":"BoundaryML/baml","slug":"could-not-unify-enum-with","errorCode":null,"errorMessage":"Could not unify Enum {} with {:?}","messagePattern":"Could not unify Enum (.+?) with (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-core/src/ir/ir_helpers/mod.rs","lineNumber":347,"sourceCode":"            {\n                Ok(BamlValueWithMeta::Media(m, (meta, field_type)))\n            }\n            BamlValueWithMeta::Media(_, _) => {\n                anyhow::bail!(\"Could not unify Media with {:?}\", field_type)\n            }\n\n            BamlValueWithMeta::Enum(name, val, meta) => {\n                if self.is_subtype(\n                    &TypeIR::Enum {\n                        name: name.clone(),\n                        dynamic: false,\n                        meta: Default::default(),\n                    },\n                    &field_type,\n                ) {\n                    Ok(BamlValueWithMeta::Enum(name, val, (meta, field_type)))\n                } else {\n                    anyhow::bail!(\"Could not unify Enum {} with {:?}\", name, field_type)\n                }\n            }\n\n            BamlValueWithMeta::Class(name, fields, meta) => {\n                if !self.is_subtype(&TypeIR::class(name.as_str()), &field_type) {\n                    anyhow::bail!(\"Could not unify Class {} with {:?}\", name, field_type);\n                } else {\n                    let class_fields = self.class_fields(&name)?;\n                    let mapped_fields = fields\n                        .into_iter()\n                        .map(|(k, v)| {\n                            let field_type = match class_fields.get(k.as_str()) {\n                                Some(ft) => ft.clone(),\n                                None => infer_type_with_meta(&v).unwrap_or(UNIT_TYPE.clone()),\n                            };\n                            let mapped_field = self.distribute_type_with_meta(v, field_type)?;\n                            Ok((k, mapped_field))\n                        })","sourceCodeStart":329,"sourceCodeEnd":365,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-core/src/ir/ir_helpers/mod.rs#L329-L365","documentation":"An Enum value's variant name could not be unified with the expected TypeIR: `is_subtype(enum_type, field_type)` failed in distribute_type_with_meta. The declared type must be the same enum (or an alias/union containing it), otherwise the value cannot be typed and the pass bails.","triggerScenarios":"distribute_type over BamlValueWithMeta::Enum(name, ..) where field_type is a different enum, a string, or a union that excludes this enum — typically while validating function arguments against the .baml schema.","commonSituations":"Two enums with similar names being mixed up after a rename; sending an enum value where a string-literal union is expected; dynamic enums disabled while the value came from dynamic input.","solutions":["Type the parameter as the correct enum in the .baml file (the one whose name appears in the error)","If multiple enums are valid, declare a union `EnumA | EnumB`","Convert the enum value to a string on the caller side if the schema expects string","Check enum name spelling/case in both the .baml schema and the caller payload"],"exampleFix":"// before (.baml)\nfunction Pick(choice: Color) -> string { ... }\n// caller sends an Animal enum value\n\n// after (.baml)\nfunction Pick(choice: Color | Animal) -> string { ... }","handlingStrategy":"validation","validationCode":"function validateEnumArg(enumName: string, declaredType: string): boolean {\n  return declaredType === enumName || declaredType.split('|').map(s => s.trim()).includes(enumName);\n}","typeGuard":"const isEnumValue = <T extends Record<string, string>>(e: T, v: string): v is T[keyof T] =>\n  Object.values(e).includes(v);","tryCatchPattern":null,"preventionTips":["Send enum values only for parameters typed as that exact enum","Use generated SDK enum types instead of raw strings","After renaming an enum in .baml, update every call site","Use unions when several enums are acceptable"],"tags":["rust","type-system","baml","enum"],"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"}