High severity intermediate · Fix: 5-10 min

ValidationException

botocore.exceptions.ValidationException

What this error means
AWS Bedrock API rejects the request because the request body is malformed or missing required fields.

Stack trace

traceback
botocore.exceptions.ValidationException: An error occurred (ValidationException) when calling the InvokeModel operation: Request body is invalid
QUICK FIX
Validate and serialize your request body JSON carefully, ensuring all required fields and correct types per AWS Bedrock API before invoking the model.

Why it happens

AWS Bedrock expects the request body to strictly follow the API schema, including required parameters and correct JSON structure. If the request body is missing required fields, contains invalid JSON, or has incorrect parameter types, the service returns a ValidationException indicating the request body is invalid.

Detection

Enable detailed logging of the request payload before sending to AWS Bedrock and validate JSON structure and required fields programmatically to catch errors early.

Causes & fixes

1

Request body JSON is malformed or not valid JSON

✓ Fix

Ensure the request body is properly serialized JSON using json.dumps() and validate JSON syntax before sending.

2

Missing required parameters in the request body as per AWS Bedrock API specification

✓ Fix

Add all required parameters exactly as specified in the AWS Bedrock API documentation to the request body.

3

Incorrect data types or unexpected fields in the request body

✓ Fix

Verify that all fields match the expected data types and remove any unsupported or extra fields.

4

Using incorrect API method or parameters incompatible with the chosen AWS Bedrock model

✓ Fix

Confirm you are calling the correct API method with parameters supported by the model and AWS Bedrock version.

Code: broken vs fixed

Broken - triggers the error
python
import boto3

client = boto3.client('bedrock')

# Missing required 'body' parameter or malformed JSON
response = client.invoke_model(ModelId='my-model', Body='invalid-json')  # This line triggers ValidationException
print(response)
Fixed - works correctly
python
import os
import json
import boto3

client = boto3.client('bedrock',
                      aws_access_key_id=os.environ['AWS_ACCESS_KEY_ID'],
                      aws_secret_access_key=os.environ['AWS_SECRET_ACCESS_KEY'],
                      region_name=os.environ.get('AWS_REGION', 'us-east-1'))

request_body = {
    "inputText": "Hello, Bedrock!"
}

response = client.invoke_model(
    ModelId='my-model',
    Body=json.dumps(request_body)  # Fixed: properly serialized JSON with required fields
)
print(response)
Fixed by properly serializing the request body as JSON with required fields and passing it to the invoke_model call, preventing the ValidationException.

Workaround

Catch ValidationException and log the raw request body for manual inspection; optionally, use a JSON schema validator locally before sending requests to Bedrock.

Prevention

Implement strict request body validation using JSON schemas or data models before sending requests to AWS Bedrock to ensure compliance with API requirements and avoid malformed requests.

Python 3.9+ · boto3 >=1.26.0 · tested on 1.28.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.