BoundaryML/baml · error
BAML internal error (AWSBedrock): file should have been reso
Error message
BAML internal error (AWSBedrock): file should have been resolved to base64
What it means
When building a Bedrock message containing an Image, BAML expects every BamlMedia with BamlMediaContent::File to have been converted to base64/url data in an earlier resolution pass. If a raw File variant survives into to_media_message, this internal invariant is broken and BAML bails. It signals a bug in BAML's media resolution pipeline rather than a user input the AWS API rejected.
Source
Thrown at engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs:1154
fn to_media_message(
&self,
media: &baml_types::BamlMedia,
) -> Result<bedrock::types::ContentBlock> {
match media.media_type {
BamlMediaType::Image => {
let format = bedrock::types::ImageFormat::from(
{
let mime_type = media.mime_type_as_ok()?;
match mime_type.strip_prefix("image/") {
Some(s) => s.to_string(),
None => mime_type,
}
}
.as_str(),
);
match &media.content {
BamlMediaContent::File(_) => {
anyhow::bail!(
"BAML internal error (AWSBedrock): file should have been resolved to base64"
)
}
BamlMediaContent::Url(url) => Ok(bedrock::types::ContentBlock::Image(
bedrock::types::ImageBlock::builder()
.set_format(Some(format))
.set_source(Some(bedrock::types::ImageSource::S3Location(
bedrock::types::S3Location::builder()
.set_uri(Some(url.url.clone()))
.build()
.context("Failed to build S3Location block")?,
)))
.build()
.context("Failed to build Image block")?,
)),
BamlMediaContent::Base64(b64_media) => Ok(bedrock::types::ContentBlock::Image(
bedrock::types::ImageBlock::builder()
.set_format(Some(format))View on GitHub (pinned to bd85ce9dee)
Solutions
- Upgrade BAML to the latest version — this is an internal invariant failure, likely already fixed.
- Pass the image as base64 data or a URL instead of a raw file path reference.
- Explicitly set media_type/mime so the resolver recognizes and resolves the file.
- File a bug report with the baml-lang/baml repo including the media input that triggered it.
Example fix
// before
image baml_image({ url: "file://./cat.png" })
// after — ensure file resolves, or inline base64
image baml_image({ url: "data:image/png;base64,<base64-data>" }) Defensive patterns
Strategy: validation
Validate before calling
// Ensure media is resolved before sending to Bedrock
if (media.url && media.url.startsWith("file://")) {
media.url = "data:image/png;base64," + fs.readFileSync(stripFileScheme(media.url)).toString("base64");
} Type guard
const isResolved = (m) => typeof m.url === 'string' && (m.url.startsWith('data:') || m.url.startsWith('http')); Try / catch
try { await bamlClient.MyPrompt(...) } catch (e) { if (String(e.message).includes('should have been resolved to base64')) { /* upgrade BAML / inline base64 and retry */ } else throw e; } Prevention
- Pass images as base64 data URLs or public URLs rather than raw file paths.
- Keep BAML runtime versions current; this is an internal invariant error.
- Set explicit media_type on media inputs.
When it happens
Trigger: Calling an AWS Bedrock client with an image media argument whose content is still a file path reference (BamlMediaContent::File) at request-build time — i.e. the media resolver failed to inline the file as base64 before to_media_message runs.
Common situations: Hitting a BAML runtime bug in a version where a file:// or relative-path image was not resolved (e.g. unusual file paths, missing file resolution for certain providers), or constructing media programmatically via internal APIs without running 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): Pdf file should have been
- BAML internal error (AWSBedrock): video file should have bee
- BAML internal error (google-ai): file should have been resol
- BAML internal error (Vertex): file should have been resolved
- VM internal error: {0}
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/72e4cde3a9e68902.
Report an issue: GitHub.