{"record":{"id":"99fc55af56beb63d","repo":"BoundaryML/baml","slug":"could-not-unify-media-with","errorCode":null,"errorMessage":"Could not unify Media with {:?}","messagePattern":"Could not unify Media with (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-core/src/ir/ir_helpers/mod.rs","lineNumber":333,"sourceCode":"                    .map(|i| {\n                        item_type(self, &field_type)\n                            .ok_or(anyhow::anyhow!(\"Could not infer child type\"))\n                            .and_then(|item_type| self.distribute_type_with_meta(i, item_type))\n                    })\n                    .collect::<Result<Vec<_>>>()?;\n                Ok(BamlValueWithMeta::List(new_items, (meta, field_type)))\n            }\n\n            BamlValueWithMeta::Media(m, meta)\n                if self.is_subtype(\n                    &TypeIR::Primitive(TypeValue::Media(m.media_type), Default::default()),\n                    &field_type,\n                ) =>\n            {\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) => {","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-core/src/ir/ir_helpers/mod.rs#L315-L351","documentation":"A Media value (image/audio/pdf etc.) could not be unified with the expected TypeIR: `is_subtype(media_primitive, field_type)` failed in distribute_type_with_meta, so the pass bails instead of tagging the value. The declared type must accept the specific media kind.","triggerScenarios":"distribute_type over BamlValueWithMeta::Media when field_type is `string`, `image` vs `audio` mismatch, or any non-media type — e.g. passing an image where the parameter is declared string, or an audio where image is expected.","commonSituations":"Attaching a base64/file media object to a prompt parameter declared as `string`; swapping input media kinds (image -> audio) without updating the .baml signature; older schemas where media params were strings.","solutions":["Declare the parameter with the correct media type, e.g. `image` or `audio`, in the .baml function signature","Ensure the media kind in the value matches the declared media type (image file for `image`, audio for `audio`)","If both kinds are allowed, use a union such as `image | audio`","If the parameter should be plain text, convert the media to a string/URL before calling"],"exampleFix":"// before (.baml)\nfunction Describe(pic: string) -> string { ... }\n// caller attaches an image media value\n\n// after (.baml)\nfunction Describe(pic: image) -> string { ... }","handlingStrategy":"validation","validationCode":"function validateMediaArg(media: { kind: string }, declaredType: string): boolean {\n  return declaredType === media.kind || declaredType.split('|').map(s => s.trim()).includes(media.kind);\n}","typeGuard":"const isImageMedia = (m: { kind: string }): m is { kind: 'image' } => m.kind === 'image';","tryCatchPattern":null,"preventionTips":["Match media kind (image/audio/pdf) to the declared .baml type","Use unions (`image | audio`) when multiple kinds are valid","Never pass media objects to string-typed params; pass URLs/base64 strings instead","Keep generated client media wrappers in sync with .baml"],"tags":["rust","type-system","baml","media"],"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"}