{"record":{"id":"711b560faa17f002","repo":"BoundaryML/baml","slug":"baml-internal-error-google-ai-file-should-have-been-resolved","errorCode":null,"errorMessage":"BAML internal error (google-ai): file should have been resolved to base64","messagePattern":"BAML internal error \\(google-ai\\): file should have been resolved to base64","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/llm_client/primitive/google/googleai_client.rs","lineNumber":385,"sourceCode":"                content.insert(\n                    \"inline_data\".into(),\n                    json!({\n                        \"mime_type\": media.mime_type_as_ok()?,\n                        \"data\": data.base64\n                    }),\n                );\n                Ok(content)\n            }\n            BamlMediaContent::Url(data) => {\n                // Pass through external media via `file_data` as required by Gemini API.\n                let mut file_data = json!({ \"file_uri\": data.url });\n                if let Some(mime) = &media.mime_type {\n                    file_data[\"mime_type\"] = json!(mime);\n                }\n                content.insert(\"file_data\".into(), file_data);\n                Ok(content)\n            }\n            BamlMediaContent::File(_) => anyhow::bail!(\n                \"BAML internal error (google-ai): file should have been resolved to base64\"\n            ),\n        }\n    }\n\n    fn role_to_message(\n        &self,\n        content: &RenderedChatMessage,\n    ) -> Result<serde_json::Map<String, serde_json::Value>> {\n        let mut message = serde_json::Map::new();\n        message.insert(\"role\".into(), json!(content.role));\n        message.insert(\n            \"parts\".into(),\n            json!(self.parts_to_message(&content.parts)?),\n        );\n        Ok(message)\n    }\n}","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/primitive/google/googleai_client.rs#L367-L403","documentation":"Google AI media messages must have their content resolved to base64 or URL before to_media_message builds inline_data/file_data payloads. A surviving BamlMediaContent::File means the resolution pass did not inline the file, so BAML treats it as a broken internal invariant and bails.","triggerScenarios":"Sending image/video/pdf media with an unresolved File content reference to a google-ai client — i.e. the file-to-base64 resolution step failed or was bypassed before message construction.","commonSituations":"Referencing a local media file that BAML failed to resolve (bad path, build/version bug) in a google-ai backed prompt, or programmatically constructed media that skips resolution.","solutions":["Upgrade BAML to the latest version.","Pass the media as a public URL or inline base64 data instead of a raw file reference.","Verify the referenced file exists and is readable so resolution can succeed.","Report a repro to baml-lang/baml if a valid file reference still fails."],"exampleFix":"// before\nimg baml_image({ url: \"file://./photo.jpg\" }) // unresolved\n// after\nimg baml_image({ url: \"data:image/jpeg;base64,<base64-data>\" })","handlingStrategy":"validation","validationCode":"if (media.url?.startsWith('file://')) { media.url = 'data:' + mime + ';base64,' + fs.readFileSync(media.url.slice(7)).toString('base64'); }","typeGuard":"const isResolvedMedia = (m) => typeof m.url === 'string' && (m.url.startsWith('data:') || m.url.startsWith('http'));","tryCatchPattern":"try { await b.GoogleAiPrompt(media) } catch (e) { if (String(e).includes('google-ai): file should have been resolved')) { /* inline base64 / upgrade BAML */ } else throw e; }","preventionTips":["Send URLs or base64 data to google-ai clients, not raw file refs.","Ensure referenced files exist and are readable.","Keep the BAML runtime version current."],"tags":["google-ai","media","internal-error","base64"],"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-14T05:17:10.506Z"}