How do I resolve validation exceptions in Amazon Bedrock?

4 minute read
0

I want to resolve my validation exceptions when I invoke in Amazon Bedrock foundational models.

Resolution

Validation errors occur when you run the model invocation APIs for InvokeModel or InvokeModelWithResponseStream APIs on a foundation model that uses an incorrect inference parameter or corresponding value. These errors occur when you use an inference parameter for one model with a model that doesn't have the same API parameter. Validation errors also occur when you use an AWS Identity and Access Management (IAM) role policy to access the foundation model without permissions.

Insufficient permissions

If you invoke an Amazon Bedrock model that uses an IAM role or IAM user without permissions, you get the following error:

"An error occurred (ValidationException) when calling the InvokeModelWithResponseStream operation: Your AWS account is not authorized to invoke this API operation."

To resolve this error, make sure that the policy for your IAM user or role has permission to invoke Amazon Bedrock models.

Incorrect model identifier

If you invoke a Amazon Bedrock model with an incorrect foundation model identifier, you get the following error:

"Error raised by bedrock service: An error occurred (ValidationException) when calling the InvokeModel operation: The provided model identifier is invalid."

To resolve this error, make sure that you use and pass the model ID of the Amazon Bedrock model that you invoke. Also, check the specific model availability for your AWS Region. For more information, see Get information about foundation models.

Incorrect guardrail input format

If you invoke a Amazon Bedrock model with incorrect guardrail input, you get the following error:

"An error occurred (ValidationException) when calling the InvokeModel operation: Guardrail was enabled but input is in incorrect format."

To resolve this error, make sure that you provide one valid Guardrail ID for guardrail-identifier and only the version number for guardrailVersion.

Malformed input request

If you invoke a Amazon Bedrock model with an incorrect input request, you get the following error:

"ValueError: Error raised by bedrock service: An error occurred (ValidationException) when calling the InvokeModel operation: Malformed input request: extraneous key [textGenerationConfig] is not permitted, please reformat your input and try again."

To resolve this error, make sure that you send an input configuration that's supported by the specific model when you invoke.

Input exceeds quota for model

If the total number of your input and output tokens is higher than the specified quota, then you get the following error:

"ValidationException('An error occurred (ValidationException) when calling the InvokeModel operation: Input is too long for requested model.')"}}."

To resolve this error, make sure that you provide input to the model within the quota of the model. This quota is a combination of your input token size and output token request.

Not supported API

If you use API that's not supported by the model to invoke an Amazon Bedrock model, you get the following error:

"ValidationException: "claude-3-sonnet-20240229" is not supported on this API. Please use the Messages API instead.(short issue description)"

To resolve this error, adjust the code to follow the Anthropic Claude Messages API that's supported in Claude 3.0. If you use Claude models, then it's a best practice to migrate to the new Messages API. The messages element represents a list of JSON objects that include the role and content for each turn in an input.

Unsupported countries, regions, or territories

If you try to access or invoke Amazon Bedrock models from unsupported Regions, you get the following error:

"Can't invoke 'us.anthropic.claude-3-haiku-20240307-v1:0'. Reason: An error occurred (ValidationException) when calling the Converse operation: Access to Anthropic models is not allowed from unsupported countries, regions, or territories. Please refer to https://www.anthropic.com/supported-countries for more information on the countries and regions Anthropic currently supports."

To resolve this error, access Amazon Bedrock models from supported Regions and make sure that your AWS account Tax Address has a supported Region. Regions include, but aren't limited to, your account's tax address and billing address, location of the machine that's trying to access Amazon Bedrock models.

To update your billing information, see How do I add or update billing contact information?

Related information

Test a guardrail

Inference request parameters and response fields for foundation models.

2 Comments

It took considerable effort to figure out how to correctly make a request to the DeepSeek R1 model on Bedrock. The example currently provided appears to be incorrect and consistently results in a validation error.

The error returned:

{ "message": "Validation Error" }

Or in Python:

Error querying model: An error occurred (ValidationException) when calling the InvokeModel operation: Validation Error

The example currently shown is:

{ "modelId": "deepseek.r1-v1:0", "contentType": "application/json", "accept": "application/json", "body": { "inferenceConfig": { "max_tokens": 512 }, "messages": [ { "role": "user", "content": "this is where you place your input text" } ] } }

Please consider updating the main model page template with a working example, as the current one can lead to confusion and wasted time during integration. Provideing link to the documention from model catlog could be usefull too.

Thank you.

replied 21 days ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

profile pictureAWS
MODERATOR
replied 21 days ago