BoundaryML/baml · error

BAML internal error (AWSBedrock): Pdf file should have been

Error message

BAML internal error (AWSBedrock): Pdf file should have been resolved to base64

What it means

For PDF media, the AWS Bedrock code path requires the BamlMedia content to already be resolved to base64 or a URL. A surviving BamlMediaContent::File variant means the pre-send resolution pass did not run/complete, so to_media_message raises this internal invariant error instead of sending a file path to Bedrock.

Source

Thrown at engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs:1184

                            )))
                            .build()
                            .context("Failed to build Image block")?,
                    )),
                    BamlMediaContent::Base64(b64_media) => Ok(bedrock::types::ContentBlock::Image(
                        bedrock::types::ImageBlock::builder()
                            .set_format(Some(format))
                            .set_source(Some(bedrock::types::ImageSource::Bytes(Blob::new(
                                aws_smithy_types::base64::decode(b64_media.base64.clone())?,
                            ))))
                            .build()
                            .context("Failed to build image block")?,
                    )),
                }
            }
            BamlMediaType::Pdf => {
                match &media.content {
                    BamlMediaContent::File(_) => {
                        anyhow::bail!(
                            "BAML internal error (AWSBedrock): Pdf file should have been resolved to base64"
                        )
                    }
                    BamlMediaContent::Url(url_media) => {
                        // AWS Bedrock supports Pdf as document type via URL
                        Ok(bedrock::types::ContentBlock::Document(
                            bedrock::types::DocumentBlock::builder()
                                .set_format(Some(bedrock::types::DocumentFormat::Pdf))
                                .set_name(Some("document".to_string())) // Default name for URL-based Pdfs
                                .set_source(Some(bedrock::types::DocumentSource::Bytes(Blob::new(
                                    url_media.url.as_bytes().to_vec(),
                                ))))
                                .set_citations(Some(
                                    CitationsConfig::builder().set_enabled(Some(true)).build()?,
                                ))
                                .build()
                                .context("Failed to build Pdf document block")?,
                        ))

View on GitHub (pinned to bd85ce9dee)

Solutions

  1. Upgrade BAML to the latest version.
  2. Supply the PDF as a URL or base64-encoded data instead of an unresolved file reference.
  3. Verify the file path is valid so the resolver can load and inline it as base64.
  4. Report the issue to the BAML maintainers with a reproduction.

Example fix

// before
pdf baml_pdf({ url: "file://./report.pdf" }) // not resolved by runtime
// after
pdf baml_pdf({ url: "data:application/pdf;base64,<base64-data>" })
Defensive patterns

Strategy: validation

Validate before calling

if (pdf.url?.startsWith('file://')) { pdf.url = 'data:application/pdf;base64,' + fs.readFileSync(pdf.url.slice(7)).toString('base64'); }

Type guard

const isResolvedPdf = (m) => typeof m.url === 'string' && (m.url.startsWith('data:application/pdf') || m.url.startsWith('http'));

Try / catch

try { await b.PdfPrompt(pdf) } catch (e) { if (String(e).includes('Pdf file should have been resolved')) throw new Error('Inline the PDF as base64 before sending to Bedrock', { cause: e }); throw e; }

Prevention

When it happens

Trigger: Sending a PDF document (BamlMediaType::Pdf) to an AWS Bedrock client where the content is still an unresolved File reference at message-build time.

Common situations: Passing a local PDF file path to a Bedrock-backed prompt in a BAML version with a resolution bug, or media constructed through internal APIs bypassing the file-to-base64 resolution step.

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


AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12). Data as JSON: /api/errors/ac4954c31c4a128c. Report an issue: GitHub.