{"record":{"id":"4460e68cfe109679","repo":"BoundaryML/baml","slug":"generic-media-cannot-inhabit-a-concrete-prompt-part","errorCode":null,"errorMessage":"generic media cannot inhabit a concrete prompt part","messagePattern":"generic media cannot inhabit a concrete prompt part","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_vm/src/package_baml/prompt.rs","lineNumber":375,"sourceCode":"fn prompt_metadata_value(vm: &mut BexVm, metadata: serde_json::Value) -> Value {\n    let metadata = match metadata {\n        serde_json::Value::Object(_) => metadata,\n        _ => serde_json::Value::Object(serde_json::Map::new()),\n    };\n    super::json::serde_to_value(vm, &metadata)\n}\n\nfn prompt_content_values(vm: &mut BexVm, content: &PromptAstSimple) -> Vec<Value> {\n    match content {\n        PromptAstSimple::String(text) => vec![Value::object(vm.alloc_string(text.clone()))],\n        PromptAstSimple::Media(media) => {\n            let class_name = match media.kind {\n                baml_type::MediaKind::Image => \"baml.media.Image\",\n                baml_type::MediaKind::Audio => \"baml.media.Audio\",\n                baml_type::MediaKind::Video => \"baml.media.Video\",\n                baml_type::MediaKind::Pdf => \"baml.media.Pdf\",\n                baml_type::MediaKind::Generic => {\n                    panic!(\"generic media cannot inhabit a concrete prompt part\")\n                }\n            };\n            let class = vm.resolve_class(class_name);\n            let data = Value::object(vm.alloc_rust_data(media.clone()));\n            vec![Value::object(vm.alloc_instance(class, vec![data]))]\n        }\n        PromptAstSimple::Multiple(parts) => parts\n            .iter()\n            .flat_map(|part| prompt_content_values(vm, part.as_ref()))\n            .collect(),\n    }\n}\n\nimpl BamlNamespaceInternal for PackageAiImpl {\n    fn assemble_prompt(vm: &mut BexVm, parts: &[Value], values: &[Value]) -> NativeCallResult {\n        let mut pending = Vec::new();\n        for value in values.iter().copied() {\n            if prompt_role(vm, value).is_none()","sourceCodeStart":357,"sourceCodeEnd":393,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_vm/src/package_baml/prompt.rs#L357-L393","documentation":"This panic fires when the BAML VM tries to render a media value into a concrete prompt part but the media's kind is `Generic`. Generic media is a placeholder/type-level carrier that has no concrete prompt class (Image/Audio/Video/Pdf), so the VM treats its presence in a prompt as an unrecoverable compiler/VM invariant violation rather than a user error.","triggerScenarios":"Calling prompt construction (prompt_content_values, reached via messages) with a value whose MediaKind is Generic — e.g. media produced by a generic-typed field or API path that did not specialize to image/audio/video/pdf before being placed into a prompt part.","commonSituations":"Assigning a generically-typed media (e.g. from a `media` union or dynamic input) directly into a prompt; a type-checking gap that let unspecialized media reach prompt rendering; wiring a media value read from external data without refining its kind.","solutions":["Ensure the media value is a concrete kind (Image/Audio/Video/Pdf) before inserting it into a prompt part; construct it via the corresponding media constructor.","Check the static type of the field/expression feeding the prompt; if it is generic media, narrow or convert it explicitly.","Report this to the BAML maintainers if a well-typed program hits it — it indicates a VM invariant leak."],"exampleFix":"// before (generic media flowing into prompt)\nprompt: media_value\n// after\nprompt: media_value as baml.media.Image  // ensure concrete media kind is used","handlingStrategy":"type-guard","validationCode":"// before inserting media into a prompt\nif media.kind == \"Generic\" { throw new Error(\"media must be a concrete kind (image/audio/video/pdf) before use in a prompt\"); }","typeGuard":"function isConcreteMedia(m) { return m && m.kind !== undefined && [\"Image\",\"Audio\",\"Video\",\"Pdf\"].includes(m.kind); }","tryCatchPattern":null,"preventionTips":["Only pass media constructed via concrete media constructors into prompt parts.","Narrow generic media types before prompt use.","Keep type annotations strict so unspecialized media cannot reach prompts."],"tags":["vm-panic","invariant","media","prompt"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}