Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation Exception : Invalid Request when calling start_async_invoke [bedrock-runtime] #4382

Open
1 task
gshr opened this issue Jan 3, 2025 · 1 comment
Labels
bedrock-runtime bug This issue is a confirmed bug. p2 This is a standard priority issue response-requested Waiting on additional information or feedback.

Comments

@gshr
Copy link

gshr commented Jan 3, 2025

Describe the bug

I am using boto3 to connect bedrock-runtime and invoke model mistral.mistral-small-2402-v1:0 using start_async_invoke. However , the error message occur when i execute the code

ERROR:root:Failed to start async invoke: An error occurred (ValidationException) when calling the StartAsyncInvoke operation: The provided request is not valid
ERROR:root:An error occurred: An error occurred (ValidationException) when calling the StartAsyncInvoke operation: The provided request is not valid

And this is my implementation:

import boto3
import json
import uuid
import logging

logging.basicConfig(level=logging.INFO)

def invoke_async(prompt: str, s3_uri: str):
    try:
        client = boto3.client('bedrock-runtime', region_name='us-east-1')
        request_token = str(uuid.uuid4())

        model_input = {
            "prompt": f"<s>[INST] {prompt} [/INST]",
            "max_tokens": 200
        }


        response = client.start_async_invoke(
            clientRequestToken=request_token,
            modelId="mistral.mistral-small-2402-v1:0",
            modelInput=json.dumps(model_input),
            outputDataConfig={
                's3OutputDataConfig': {
                    's3Uri': s3_uri
                }
            }
        )
        print(response)

        logging.info(f"Task started. Request token: {request_token}")
        return request_token
    except Exception as e:
        logging.error(f"Failed to start async invoke: {e}")
        raise

if __name__ == "__main__":
    try:
        invoke_async(
            prompt="What is artificial intelligence?",
            s3_uri="s3://bucket-name/"
        )
    except Exception as e:
        logging.error(f"An error occurred: {e}")

Regression Issue

  • Select this option if this issue appears to be a regression.

Expected Behavior

Success Response from api

Current Behavior

INFO:botocore.credentials:Found credentials in shared credentials file: ~/.aws/credentials
ERROR:root:Failed to start async invoke: An error occurred (ValidationException) when calling the StartAsyncInvoke operation: The provided request is not valid
ERROR:root:An error occurred: An error occurred (ValidationException) when calling the StartAsyncInvoke operation: The provided request is not valid

Reproduction Steps

Replace s3_uri with your bucket in implementation above

Possible Solution

No response

Additional Information/Context

No response

SDK version used

1.35.91

Environment details (OS name and version, etc.)

macOS

@gshr gshr added bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels Jan 3, 2025
@khushail
Copy link

Hi @gshr, thanks for reaching out.

On AWS Bedrock Runtime docs page, I found this reference article for getting validationExceptionError -
https://docs.aws.amazon.com/bedrock/latest/APIReference/API_runtime_StartAsyncInvoke.html#API_runtime_StartAsyncInvoke_Errors

It would be helpful if you could please share the complete debug logs with us to get to the root cause. You could use this command for getting the debug logs -

boto3.set_stream_logger('')

Thanks

@khushail khushail added response-requested Waiting on additional information or feedback. p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Jan 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bedrock-runtime bug This issue is a confirmed bug. p2 This is a standard priority issue response-requested Waiting on additional information or feedback.
Projects
None yet
Development

No branches or pull requests

2 participants