ai icon indicating copy to clipboard operation
ai copied to clipboard

amazon bedrock package incorrectly extracting mimetype from files

Open jmmander opened this issue 9 months ago • 1 comments

Description

When I send a XLXS file to amazon bedrock (using model claude 3.7) using the amazon-bedrock package, i get the following error:

validation errors detected: Value at 'messages.3.member.content.3.member.document.format' failed to satisfy constraint: 
Member must satisfy enum value set: [docx, csv, html, txt, pdf, md, doc, xlsx, xls]; 

I think this happens here where you are extracting the mimetype:

     bedrockContent.push({
                      document: {
                        format: part.mimeType?.split(
                          '/',
                        )?.[1] as BedrockDocumentFormat,
                        name: generateFileId(),
                        source: {
                          bytes: part.data,
                        },
                      },
                    });

Additionally i think the BedrockDocumentFormat type is overly strict with only 3 file types supported. These are the supported types from amazon bedrocks api reference: https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_DocumentBlock.html

Code example

No response

AI provider

@ai-sdk/amazon-bedrock 2.2.4

Additional context

No response

jmmander avatar Apr 08 '25 15:04 jmmander

We're experiencing the same with .docx files. .pdf files works fine. I guess this supports the hunch of it being due to the code you're referencing, given that these are the mimetypes we use:

// file extension: mimetype
{
  '.pdf': 'application/pdf',
  '.doc': 'application/msword',
  '.docx': 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
}

vnd.openxmlformats-officedocument.wordprocessingml.document is not the correct value to send as format.

hanshenrik avatar Apr 16 '25 08:04 hanshenrik

as of 2025-06-11, using versions @ai-sdk/[email protected] and [email protected], this bug still exists. Luckily, @christian-bromann 's PR, https://github.com/vercel/ai/pull/6185, fixes the issue, but has not been reviewed for over a month.

I know Amazon Bedrock might not be as flashy as other providers, but it’s still a popular choice for enterprise LLM workloads, and this feature not working as expected hurts the AI SDK's perceived viability for new enterprise customers.

brianprost avatar Jun 11 '25 13:06 brianprost

It would be great if the PR would get a review and be merged. 😇

cofenster-micha avatar Jun 20 '25 16:06 cofenster-micha

+1 faced this issue with .txt with AI SDK v5 alpha 15

[Error [AI_APICallError]: undefined: 1 validation error detected: Value at 'messages.5.member.content.1.member.document.format' failed to satisfy constraint: Member must satisfy enum value set: [docx, csv, html, txt, pdf, md, doc, xlsx, xls]] {
  cause: undefined,
  url: 'https://bedrock-runtime.us-west-2.amazonaws.com/model/us.anthropic.claude-sonnet-4-20250514-v1%3A0/converse-stream',
  requestBodyValues: [Object],
  statusCode: 400,
  responseHeaders: [Object],
  responseBody: `{"message":"1 validation error detected: Value at 'messages.5.member.content.1.member.document.format' failed to satisfy constraint: Member must satisfy enum value set: [docx, csv, html, txt, pdf, md, doc, xlsx, xls]"}`,
  isRetryable: false,
  data: [Object]
}

maybe @dancer can help on this in order to fix it for next alpha releases of v5

arthberman avatar Jun 22 '25 09:06 arthberman

+1 faced this issue with .txt with AI SDK v5 alpha 15

Did you get that error with testing the PR or from the main branch? I hadn't tested with the v5 yet

brianprost avatar Jun 22 '25 23:06 brianprost

@brianprost tested without the PR, but with latest v5 alpha release

arthberman avatar Jun 23 '25 08:06 arthberman

thank you for the ping will look into this now and check the pr

dancer avatar Jun 25 '25 09:06 dancer

just wanted to check does this issue still occur in aisdk v5 beta if someone could let me know @arthberman @brianprost

dancer avatar Jun 25 '25 09:06 dancer

@dancer yes it occurs with v5 beta too. Thks!

arthberman avatar Jun 25 '25 14:06 arthberman

fixing now

dancer avatar Jun 26 '25 10:06 dancer

mb took a while, landed there now will be part of our next beta release

dancer avatar Jun 30 '25 17:06 dancer

ty for being patient

dancer avatar Jun 30 '25 17:06 dancer