boto3amazon-bedrock

ValidationException: Unable to Process Provided Image in Amazon Bedrock Converse API Call


I'm using boto3 to interact with the Amazon Bedrock runtime API, trying to submit both text and an image (in base64 format) to the converse operation. However, I'm getting the following error:

ValidationException: An error occurred (ValidationException) when calling the Converse operation: The model returned the following errors: Unable to process provided image.

Here is a snippet of the code:

import boto3
import json

config = {
    "additionalModelRequestFields": {},
    "inferenceConfig": {
        "maxTokens": 512,
        "temperature": 0.5,
        "topP": 0.9
    },
    "messages": [
        {
            "content": [
                {"text": "What is this document?"},
                {"image": {"format": "jpeg", "source": {"bytes": img_base64_str}}}
            ],
            "role": "user"
        }
    ]
}

body = json.dumps(config)

client = boto3.client('bedrock-runtime', region_name='us-east-1', aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key)

model_id = 'us.meta.llama3-2-11b-instruct-v1:0'

response = client.converse(inferenceConfig=config['inferenceConfig'], messages=config['messages'], modelId=model_id)

Has anyone experienced this issue when sending image data? Is there a specific format or setup required to process images in the converse operation?

Any help or insights would be appreciated!

I double-checked the base64 string to ensure it is valid and tried using different images, but the error persists. I'm seeking insights on any specific requirements for the image input or suggestions on how to troubleshoot this issue.


Solution

  • you are sending the image in base64.

    The Conversation api directly accepts the file content in the format you specify.

    "messages": [
        {
            "content": [
                {"text": "What is this document?"},
                {"image": {"format": "jpeg", "source": {"bytes": image_content}}}
            ],
            "role": "user"
        }
    ]
    

    where for example if you take your image from aws S3

    file_obj = s3.get_object(Bucket=bucket, Key=key)
    image_content = file_obj['Body'].read()