BoundaryML/baml · error
BAML internal error (google-ai): file should have been resol
Error message
BAML internal error (google-ai): file should have been resolved to base64
What it means
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.
Source
Thrown at engine/baml-runtime/src/internal/llm_client/primitive/google/googleai_client.rs:385
content.insert(
"inline_data".into(),
json!({
"mime_type": media.mime_type_as_ok()?,
"data": data.base64
}),
);
Ok(content)
}
BamlMediaContent::Url(data) => {
// Pass through external media via `file_data` as required by Gemini API.
let mut file_data = json!({ "file_uri": data.url });
if let Some(mime) = &media.mime_type {
file_data["mime_type"] = json!(mime);
}
content.insert("file_data".into(), file_data);
Ok(content)
}
BamlMediaContent::File(_) => anyhow::bail!(
"BAML internal error (google-ai): file should have been resolved to base64"
),
}
}
fn role_to_message(
&self,
content: &RenderedChatMessage,
) -> Result<serde_json::Map<String, serde_json::Value>> {
let mut message = serde_json::Map::new();
message.insert("role".into(), json!(content.role));
message.insert(
"parts".into(),
json!(self.parts_to_message(&content.parts)?),
);
Ok(message)
}
}View on GitHub (pinned to bd85ce9dee)
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.
Example fix
// before
img baml_image({ url: "file://./photo.jpg" }) // unresolved
// after
img baml_image({ url: "data:image/jpeg;base64,<base64-data>" }) Defensive patterns
Strategy: validation
Validate before calling
if (media.url?.startsWith('file://')) { media.url = 'data:' + mime + ';base64,' + fs.readFileSync(media.url.slice(7)).toString('base64'); } Type guard
const isResolvedMedia = (m) => typeof m.url === 'string' && (m.url.startsWith('data:') || m.url.startsWith('http')); Try / catch
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; } Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- BAML internal error (AWSBedrock): file should have been reso
- BAML internal error (AWSBedrock): Pdf file should have been
- BAML internal error (AWSBedrock): video file should have bee
- BAML internal error (Vertex): file should have been resolved
- BAML internal error (Anthropic): file should have been resol
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/711b560faa17f002.
Report an issue: GitHub.