ValidationException: Field required for CachePoint ContentBlock in AWS SDK for Java 2.32.2
Describe the bug
When using AWS SDK for Java version 2.32.2 with Amazon Bedrock Runtime, adding a CachePoint ContentBlock to a message results in a ValidationException with the error message: messages.0.content.2.type: Field required.
Error Details
software.amazon.awssdk.services.bedrockruntime.model.ValidationException:
The model returned the following errors: messages.0.content.2.type: Field required
(Service: BedrockRuntime, Status Code: 400, Request ID: 1ff03d35-55e1-4582-aefe-42600fbcb2df)
Regression Issue
- [ ] Select this option if this issue appears to be a regression.
Expected Behavior
The CachePoint ContentBlock should be accepted as a valid content block in the message, allowing for prompt caching functionality.
Current Behavior
The API returns a ValidationException indicating that a type field is required for the third ContentBlock (index 2), which is the CachePoint block.
Reproduction Steps
-
Set up Maven project with AWS SDK for Java 2.32.2:
<dependency> <groupId>software.amazon.awssdk</groupId> <artifactId>bedrockruntime</artifactId> <version>2.32.2</version> </dependency> -
Create a BedrockRuntimeClient:
BedrockRuntimeClient client = BedrockRuntimeClient.builder() .region(Region.US_EAST_1) .build(); -
Prepare a PDF document (any PDF file will work for reproduction)
-
Create ContentBlocks with CachePoint:
List<ContentBlock> messageContent = Arrays.asList( ContentBlock.builder().text("Analyze this document").build(), ContentBlock.builder() .document(DocumentBlock.builder() .format("pdf") .name("test-doc") .source(DocumentSource.builder() .bytes(SdkBytes.fromByteArray(pdfBytes)) .build()) .build()) .build(), ContentBlock.builder() .cachePoint(CachePointBlock.builder() .type(CachePointType.DEFAULT) .build()) .build() ); -
Create and send ConverseRequest:
ConverseRequest request = ConverseRequest.builder() .modelId("us.anthropic.claude-3-7-sonnet-20250219-v1:0") .messages(Message.builder() .role(ConversationRole.USER) .content(messageContent) .build()) .build(); client.converse(request); // This will throw ValidationException -
Observe the error: The call will fail with
ValidationException: messages.0.content.2.type: Field required
Note: The same code works perfectly when removing the CachePoint ContentBlock (using only text and document blocks).
Possible Solution
- Check if ContentBlock requires an explicit type field when using CachePoint
- Verify if CachePointBlock structure has changed in recent SDK versions
- Confirm if there are additional required fields for CachePoint ContentBlocks
Additional Information/Context
- The same code structure works perfectly when only using text and document ContentBlocks
- The error specifically mentions messages.0.content.2.type: Field required, suggesting the CachePoint ContentBlock is missing a required type field
- This appears to be related to the ContentBlock serialization/validation process
AWS Java SDK version used
2.32.2
JDK version used
openjdk version "21.0.6" 2025-01-21 LTS OpenJDK Runtime Environment Corretto-21.0.6.7.1 (build 21.0.6+7-LTS) OpenJDK 64-Bit Server VM Corretto-21.0.6.7.1 (build 21.0.6+7-LTS, mixed mode, sharing)
Operating System and version
mac os
Hi @ilove2git,
Thanks for reporting the issue. Prompt Caching support feature for Converse API was introduced in Java SDK v2.31.12. I can confirm that the ValidationException you encountered in the described scenario is reproducible from then, up until the most recent available version 2.32.4.
I am further checking on this with the Bedrock service team and shall get back to you as soon as I have an update on it.
Regards, Chaitanya
I can confirm that this also happens with the Python SDK (boto3/botocore 1.40.0).
Given that the error comes from amazons back-end, I suspect that this happens with all the SDKs.
@bhoradc Any update on this?
This appears to only happen if the cache point immediately follows the document. If there is a text message between the two it works.
To help python users googling the issue, the error message in python is:
botocore.errorfactory.ValidationException: An error occurred (ValidationException) when calling the ConverseStream operation: The model returned the following errors: messages.0.content.2.type: Field required
This appears to only happen if the cache point immediately follows the document. If there is a text message between the two it works.
We noticed the same so have been putting document content before text content as a workaround.
I also encountered exactly the same issue when using Golang, and the trigger condition is also when the cache point follows a document block.