aws / aws/aws-sdk-java-v2

ValidationException: Field required for CachePoint ContentBlock in AWS SDK for Java 2.32.2

Open
#6,277 7 comments 1 reaction 0 assignees View on GitHub
bug service:bedrock-runtime
Dominant language
Java
Stars
2.6k
Forks
1k
Avg merge
2d 9h
Merged PRs (30d)
51

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

1. **Set up Maven project** with AWS SDK for Java 2.32.2:
```xml

software.amazon.awssdk
bedrockruntime
2.32.2

```

2. **Create a BedrockRuntimeClient**:
```java
BedrockRuntimeClient client = BedrockRuntimeClient.builder()
.region(Region.US_EAST_1)
.build();
```

3. **Prepare a PDF document** (any PDF file will work for reproduction)

4. **Create ContentBlocks with CachePoint**:
```java
List 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()
);
```

5. **Create and send ConverseRequest**:
```java
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
```

6. **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

1. Check if ContentBlock requires an explicit type field when using CachePoint
2. Verify if CachePointBlock structure has changed in recent SDK versions
3. 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.