{"record":{"id":"ac4954c31c4a128c","repo":"BoundaryML/baml","slug":"baml-internal-error-awsbedrock-pdf-file-should-have-been","errorCode":null,"errorMessage":"BAML internal error (AWSBedrock): Pdf file should have been resolved to base64","messagePattern":"BAML internal error \\(AWSBedrock\\): Pdf file should have been resolved to base64","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs","lineNumber":1184,"sourceCode":"                            )))\n                            .build()\n                            .context(\"Failed to build Image block\")?,\n                    )),\n                    BamlMediaContent::Base64(b64_media) => Ok(bedrock::types::ContentBlock::Image(\n                        bedrock::types::ImageBlock::builder()\n                            .set_format(Some(format))\n                            .set_source(Some(bedrock::types::ImageSource::Bytes(Blob::new(\n                                aws_smithy_types::base64::decode(b64_media.base64.clone())?,\n                            ))))\n                            .build()\n                            .context(\"Failed to build image block\")?,\n                    )),\n                }\n            }\n            BamlMediaType::Pdf => {\n                match &media.content {\n                    BamlMediaContent::File(_) => {\n                        anyhow::bail!(\n                            \"BAML internal error (AWSBedrock): Pdf file should have been resolved to base64\"\n                        )\n                    }\n                    BamlMediaContent::Url(url_media) => {\n                        // AWS Bedrock supports Pdf as document type via URL\n                        Ok(bedrock::types::ContentBlock::Document(\n                            bedrock::types::DocumentBlock::builder()\n                                .set_format(Some(bedrock::types::DocumentFormat::Pdf))\n                                .set_name(Some(\"document\".to_string())) // Default name for URL-based Pdfs\n                                .set_source(Some(bedrock::types::DocumentSource::Bytes(Blob::new(\n                                    url_media.url.as_bytes().to_vec(),\n                                ))))\n                                .set_citations(Some(\n                                    CitationsConfig::builder().set_enabled(Some(true)).build()?,\n                                ))\n                                .build()\n                                .context(\"Failed to build Pdf document block\")?,\n                        ))","sourceCodeStart":1166,"sourceCodeEnd":1202,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs#L1166-L1202","documentation":"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.","triggerScenarios":"Sending a PDF document (BamlMediaType::Pdf) to an AWS Bedrock client where the content is still an unresolved File reference at message-build time.","commonSituations":"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.","solutions":["Upgrade BAML to the latest version.","Supply the PDF as a URL or base64-encoded data instead of an unresolved file reference.","Verify the file path is valid so the resolver can load and inline it as base64.","Report the issue to the BAML maintainers with a reproduction."],"exampleFix":"// before\npdf baml_pdf({ url: \"file://./report.pdf\" }) // not resolved by runtime\n// after\npdf baml_pdf({ url: \"data:application/pdf;base64,<base64-data>\" })","handlingStrategy":"validation","validationCode":"if (pdf.url?.startsWith('file://')) { pdf.url = 'data:application/pdf;base64,' + fs.readFileSync(pdf.url.slice(7)).toString('base64'); }","typeGuard":"const isResolvedPdf = (m) => typeof m.url === 'string' && (m.url.startsWith('data:application/pdf') || m.url.startsWith('http'));","tryCatchPattern":"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; }","preventionTips":["Inline PDFs as base64 data URLs for Bedrock requests.","Verify file paths exist so BAML's resolver can inline them.","Upgrade BAML if resolution is failing on valid files."],"tags":["aws-bedrock","pdf","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"}