{"record":{"id":"92cbfe7de7d4ccdb","repo":"BoundaryML/baml","slug":"please-specify-a-media-type-for-this-we-could-not-infer-one","errorCode":null,"errorMessage":"Please specify a media type for this {}; we could not infer one","messagePattern":"Please specify a media type for this (.+?); we could not infer one","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-lib/baml-types/src/media.rs","lineNumber":56,"sourceCode":"    pub content: BamlMediaContent,\n}\n\n#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]\npub enum BamlMediaContent {\n    File(MediaFile),\n    Url(MediaUrl),\n    Base64(MediaBase64),\n}\n\nimpl BamlMedia {\n    pub fn mime_type_as_ok(&self) -> Result<String> {\n        match &self.mime_type {\n            Some(mt) => Ok(mt.clone()),\n            None => {\n                if self.media_type == BamlMediaType::Pdf {\n                    Ok(\"application/pdf\".to_string())\n                } else {\n                    Err(anyhow::anyhow!(\n                        \"Please specify a media type for this {}; we could not infer one\",\n                        self.media_type\n                    ))\n                }\n            }\n        }\n    }\n    pub fn file(\n        media_type: BamlMediaType,\n        baml_path: PathBuf,\n        relpath: String,\n        mime_type: Option<String>,\n    ) -> BamlMedia {\n        Self {\n            media_type,\n            mime_type,\n            content: BamlMediaContent::File(MediaFile {\n                span_path: baml_path,","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-lib/baml-types/src/media.rs#L38-L74","documentation":"BamlMedia::mime_type_as_ok returns the media's MIME type; if it was never set, only PDFs get a default (application/pdf). For any other media type the library cannot infer a MIME type and asks the developer to specify one explicitly. The library refuses to guess Content-Type for non-PDF media.","triggerScenarios":"Constructing a BamlMedia (image/audio/video) from bytes or a URL without setting mime_type, then calling mime_type_as_ok; passing media whose Content-Type was unavailable at construction time.","commonSituations":"Loading images or audio from raw bytes where no Content-Type header exists; file uploads where the client stripped the extension; older BAML versions/schemas that didn't record media type.","solutions":["Set the media's mime_type explicitly when constructing BamlMedia (e.g. \"image/png\", \"audio/wav\").","Derive it from the file extension or HTTP Content-Type header before constructing the media value.","If the media is a PDF, note the library already defaults to application/pdf — no action needed."],"exampleFix":"// before\nlet media = BamlMedia::media(BamlMediaType::Image, url, None);\nlet mt = media.mime_type_as_ok()?;\n// after\nlet media = BamlMedia::media(BamlMediaType::Image, url, Some(\"image/png\".to_string()));\nlet mt = media.mime_type_as_ok()?;","handlingStrategy":"validation","validationCode":"if media.mime_type.is_none() && media.media_type != BamlMediaType::Pdf { return Err(anyhow!(\"must set mime_type for non-PDF media\")); }","typeGuard":"fn has_mime(m: &BamlMedia) -> bool { m.mime_type.is_some() || m.media_type == BamlMediaType::Pdf }","tryCatchPattern":"let mt = media.mime_type_as_ok().map_err(|e| anyhow!(\"set mime_type: {}\", e))?;","preventionTips":["Always set mime_type when constructing BamlMedia from bytes","Derive MIME from file extension or HTTP Content-Type at ingestion","Add a construction-time assertion for non-PDF media"],"tags":["rust","media","mime-type"],"backgroundTag":"missing-required-config-field","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"}