spring-ai icon indicating copy to clipboard operation
spring-ai copied to clipboard

Bedrock Structured Output

Open jamesward opened this issue 9 months ago • 7 comments

Some models on Bedrock now support native structured output: https://aws.amazon.com/about-aws/whats-new/2026/02/structured-outputs-available-amazon-bedrock/

Please add support in AdvisorParams.ENABLE_NATIVE_STRUCTURED_OUTPUT for this.

jamesward avatar Feb 11 '26 20:02 jamesward

Thanks for sharing this @jamesward

To add native SO support to a ChatModel, you only need to extend its ChatOptions to implement the StructuredOutputChatOptions interface.

For reference: https://github.com/spring-projects/spring-ai/blob/ac9254fa55085115274ce981de226519181845aa/models/spring-ai-openai-sdk/src/main/java/org/springframework/ai/openaisdk/OpenAiSdkChatOptions.java#L47

tzolov avatar Feb 12 '26 08:02 tzolov

Hi @jamesward @tzolov ! I've started working on this issue and submitted a PR that implements StructuredOutputChatOptions in BedrockChatOptions.

What was done

  • BedrockChatOptions now implements StructuredOutputChatOptions
  • Added outputSchema field with getter/setter and Builder support
  • Added unit tests

Current limitation

The current AWS SDK version (2.36.3) used by Spring AI does not include the OutputConfig class for the Converse API yet. So the output schema is stored as a plain String field for now, consistent with how other providers like Google GenAI handle it.

Once the AWS SDK dependency is upgraded to a version that includes OutputConfig, BedrockProxyChatModel can be updated to pass the schema to the Converse API via outputConfig.textFormat.

PR: #5501

chanani avatar Feb 25 '26 01:02 chanani

Can you bump to a newer AWS SDK to address that?

jamesward avatar Feb 25 '26 15:02 jamesward

Hello @jamesward, I believe upgrading the SDK version is not something I can decide on my own, as it may cause side effects in the existing logic.

However, I have pre-implemented the following changes in BedrockProxyChatModel so that structured output works immediately once the aws bedrockruntime SDK is upgraded to version 2.41.22 or above.

  1. Added .outputConfig(buildOutputConfig(updatedRuntimeOptions)) when building ConverseRequest in createRequest()
  2. Added .outputConfig(converseRequest.outputConfig()) when building ConverseStreamRequest in internalStream()
  3. Added outputSchema merge logic between runtime/default options in buildRequestPrompt()
  4. Added buildOutputConfig() private method — converts the outputSchema String into the OutputConfig > OutputFormat > OutputFormatStructure > JsonSchemaDefinition structure

The OutputConfig, OutputFormat, OutputFormatStructure, and JsonSchemaDefinition classes are available starting from SDK version 2.41.22, and both Converse and ConverseStream APIs support structured output.

chanani avatar Feb 26 '26 05:02 chanani

Usually AWS Java SDK updates are compatible. So it'd be great to have the required version bump in the PR. Then hopefully some automated integration tests will catch any possible regressions. I can also do some manual testing.

jamesward avatar Feb 26 '26 15:02 jamesward

Hi @jamesward,

I've updated the PR to include the AWS SDK version bump (2.36.3 → 2.41.22) and the full structured output integration in BedrockProxyChatModel.

Added:

  • buildOutputConfig() to convert outputSchema into AWS OutputConfig
  • outputConfig support for both ConverseRequest and ConverseStreamRequest
  • outputSchema merge logic between runtime/default options

Build and unit tests pass successfully.

chanani avatar Mar 01 '26 03:03 chanani

Hi @tzolov ! just wanted to gently follow up on this PR. It's been a couple of weeks since the last update and we haven't received any feedback yet. This adds native structured output support for Amazon Bedrock, which resolves #5445. Would really appreciate a review when you get a chance.

happy to make any adjustments!

chanani avatar Mar 10 '26 05:03 chanani