-
Notifications
You must be signed in to change notification settings - Fork 920
Description
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