Skip to content

Add StructuredOutputChatOptions support to BedrockChatOptions#5501

Closed
chanani wants to merge 3 commits intospring-projects:mainfrom
chanani:issue-5445
Closed

Add StructuredOutputChatOptions support to BedrockChatOptions#5501
chanani wants to merge 3 commits intospring-projects:mainfrom
chanani:issue-5445

Conversation

@chanani
Copy link
Copy Markdown
Contributor

@chanani chanani commented Feb 25, 2026

Add StructuredOutputChatOptions support to BedrockChatOptions

Summary

This PR implements the StructuredOutputChatOptions interface in BedrockChatOptions to provide the foundation for native structured output support on Amazon Bedrock.

Resolves gh-5445

Motivation

Amazon Bedrock now supports native structured output via the outputConfig.textFormat field in the Converse API. To enable AdvisorParams.ENABLE_NATIVE_STRUCTURED_OUTPUT for Bedrock, BedrockChatOptions needs to implement StructuredOutputChatOptions, which is the unified abstraction layer used across all providers (Anthropic, Google GenAI, Mistral, OpenAI, etc.).

Changes

BedrockChatOptions.java

  • Implement StructuredOutputChatOptions interface
  • Add outputSchema field with @JsonIgnore annotation
  • Add getOutputSchema() / setOutputSchema() methods
  • Add outputSchema() method to Builder
  • Add outputSchema copy logic to fromOptions()

BedrockChatOptionsTests.java

  • Add outputSchema assertions to existing tests (builder, copy, setter, defaultValues)
  • Add test for StructuredOutputChatOptions interface implementation
  • Add tests for outputSchema set/get and overwrite

Note

The current AWS SDK version (2.36.3) used by Spring AI does not yet include the OutputConfig class for the Converse API. Therefore, this PR stores the output schema as a plain String field, consistent with the approach used by other providers like Google GenAI. Once the AWS SDK is upgraded to a version that includes OutputConfig, the BedrockProxyChatModel can read this field and pass it to the Converse API request.

chanani added 3 commits March 1, 2026 12:35
Implemented StructuredOutputChatOptions interface in BedrockChatOptions
to provide the foundation for native structured output support on Amazon Bedrock.

- Implement StructuredOutputChatOptions interface
- Add outputSchema field with getter/setter
- Add outputSchema() method to Builder
- Add outputSchema copy logic to fromOptions()

Closes spring-projectsgh-5445

Signed-off-by: CHANHAN <130114269+chanani@users.noreply.github.com>
Added unit tests to verify outputSchema functionality in BedrockChatOptions.

- Add outputSchema assertions to existing tests (builder, copy, setter, defaultValues)
- Add test for StructuredOutputChatOptions interface implementation
- Add tests for outputSchema set/get and overwrite

Signed-off-by: CHANHAN <130114269+chanani@users.noreply.github.com>
- Add buildOutputConfig() to convert outputSchema into AWS OutputConfig
- Add outputConfig to ConverseRequest in createRequest()
- Add outputConfig to ConverseStreamRequest in internalStream()
- Add outputSchema merge logic between runtime/default options in buildRequestPrompt()
- Upgrade AWS bedrockruntime SDK from 2.36.3 to 2.41.22

Signed-off-by: CHANHAN <130114269+chanani@users.noreply.github.com>
@tzolov tzolov self-assigned this Mar 12, 2026
@tzolov
Copy link
Copy Markdown
Contributor

tzolov commented Mar 12, 2026

@chanani, thank you for your contribution.
As we are moving fast toward the 2.0 we improve the APIs and introduce breaking changes.
Some of those changes affect the ChatOptions API and therefore the BedrockChatOptions API.
This API has changed since your PR was submitted. I will check if we can upgrade the PR or it is easy to start from scratch.

@tzolov
Copy link
Copy Markdown
Contributor

tzolov commented Mar 12, 2026

It looks ok. I will do the rebasing before the merge.

@tzolov tzolov added this to the 2.0.0-M3 milestone Mar 12, 2026
@tzolov
Copy link
Copy Markdown
Contributor

tzolov commented Mar 12, 2026

Thanks @chanani
Rebased, update the the new chat-options/builder model, add chatclient tests, add reference docs and merge at 3003316

@tzolov tzolov closed this Mar 12, 2026
@chanani chanani deleted the issue-5445 branch March 12, 2026 13:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bedrock Structured Output

2 participants