{"record":{"id":"72e4cde3a9e68902","repo":"BoundaryML/baml","slug":"baml-internal-error-awsbedrock-file-should-have-been","errorCode":null,"errorMessage":"BAML internal error (AWSBedrock): file should have been resolved to base64","messagePattern":"BAML internal error \\(AWSBedrock\\): 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":1154,"sourceCode":"    fn to_media_message(\n        &self,\n        media: &baml_types::BamlMedia,\n    ) -> Result<bedrock::types::ContentBlock> {\n        match media.media_type {\n            BamlMediaType::Image => {\n                let format = bedrock::types::ImageFormat::from(\n                    {\n                        let mime_type = media.mime_type_as_ok()?;\n                        match mime_type.strip_prefix(\"image/\") {\n                            Some(s) => s.to_string(),\n                            None => mime_type,\n                        }\n                    }\n                    .as_str(),\n                );\n                match &media.content {\n                    BamlMediaContent::File(_) => {\n                        anyhow::bail!(\n                            \"BAML internal error (AWSBedrock): file should have been resolved to base64\"\n                        )\n                    }\n                    BamlMediaContent::Url(url) => Ok(bedrock::types::ContentBlock::Image(\n                        bedrock::types::ImageBlock::builder()\n                            .set_format(Some(format))\n                            .set_source(Some(bedrock::types::ImageSource::S3Location(\n                                bedrock::types::S3Location::builder()\n                                    .set_uri(Some(url.url.clone()))\n                                    .build()\n                                    .context(\"Failed to build S3Location block\")?,\n                            )))\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))","sourceCodeStart":1136,"sourceCodeEnd":1172,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/primitive/aws/aws_client.rs#L1136-L1172","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nimage baml_image({ url: \"file://./cat.png\" })\n// after — ensure file resolves, or inline base64\nimage baml_image({ url: \"data:image/png;base64,<base64-data>\" })","handlingStrategy":"validation","validationCode":"// Ensure media is resolved before sending to Bedrock\nif (media.url && media.url.startsWith(\"file://\")) {\n  media.url = \"data:image/png;base64,\" + fs.readFileSync(stripFileScheme(media.url)).toString(\"base64\");\n}","typeGuard":"const isResolved = (m) => typeof m.url === 'string' && (m.url.startsWith('data:') || m.url.startsWith('http'));","tryCatchPattern":"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; }","preventionTips":["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."],"tags":["aws-bedrock","media","internal-error","base64","rust"],"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"}