Skip to content

Conversation

@tzolov
Copy link
Contributor

@tzolov tzolov commented Nov 16, 2025

Add ChatClient support for utilizing native structured output capabilities provided by underlying ChatModel implementations (Anthropic, OpenAI, Vertex AI Gemini).

Implement StructuredOutputChatOptions interface to provide unified structured output
support across AI providers. This enables AI models that provide built-in structured
output to natively generate JSON responses that conform to a specified schema
without additional prompt engineering.

Models that provide structured response should implement the StructuredOutputChatOptions.
To activate the native over the ChatClient prompt-based structured output response**,**
you need to add the AdvisorParams.WITH_NATIVE_STRUCTURED_OUTPUT advisor parameter to your
ChatClient configuration.

  • Add StructuredOutputChatOptions interface with getOutputSchema/setOutputSchema methods
  • Implement interface in AnthropicChatOptions, OpenAiChatOptions, and VertexAiGeminiChatOptions
  • Update AnthropicApi to support output_format parameter and add structured-outputs-2025-11-13 beta version
  • Add ChatClientAttributes for STRUCTURED_OUTPUT_SCHEMA and STRUCTURED_OUTPUT_NATIVE
  • Enhance ChatModelCallAdvisor to set output schema when native structured output is enabled
  • Update DefaultChatClient to handle native structured output via context attributes
  • Configure BeanOutputConverter to mark all fields as required in generated JSON schemas
  • Add AdvisorParams.WITH_NATIVE_STRUCTURED_OUTPUT for easy activation via ChatClient
  • Add integration tests for native structured output across all three providers

Closes #4463
Fixes #4889
Part of #2787

@tzolov tzolov force-pushed the native-structured-output branch from 040697e to 5aff1d3 Compare November 16, 2025 21:30
@tzolov tzolov changed the title [WIP] feat: Extend ChatClient to leverage native structured output from ChatModel implementations feat: Extend ChatClient to leverage native structured output from ChatModel implementations Nov 16, 2025
@ilayaperumalg ilayaperumalg self-assigned this Nov 17, 2025
@tzolov tzolov force-pushed the native-structured-output branch 2 times, most recently from 8ba7427 to 569ac6f Compare November 19, 2025 09:14
@ghostg00
Copy link

This pull request is very much needed, I don't know when it can be used.

Implement StructuredOutputChatOptions interface to provide unified structured output
support across AI providers. This enables AI models that provide built-in structured
output to natively generate JSON responses that conform to a specified schema
without additional prompt engineering.

Models that provide structured response should implement the StructuredOutputChatOptions.
To activate the native over the ChatClient prompt-based structured output response**,**
you need to add the AdvisorParams.WITH_NATIVE_STRUCTURED_OUTPUT advisor parameter to your
ChatClient configuration.

- Add StructuredOutputChatOptions interface with getOutputSchema/setOutputSchema methods
- Implement interface in AnthropicChatOptions, OpenAiChatOptions, and VertexAiGeminiChatOptions
- Update AnthropicApi to support output_format parameter and add structured-outputs-2025-11-13 beta version
- Add ChatClientAttributes for STRUCTURED_OUTPUT_SCHEMA and STRUCTURED_OUTPUT_NATIVE
- Enhance ChatModelCallAdvisor to set output schema when native structured output is enabled
- Update DefaultChatClient to handle native structured output via context attributes
- Configure BeanOutputConverter to mark all fields as required in generated JSON schemas
- Add AdvisorParams.WITH_NATIVE_STRUCTURED_OUTPUT for easy activation via ChatClient
- Add integration tests for native structured output across all three providers

Fixes spring-projects#4889
Addresses spring-projects#4463
Part of spring-projects#2787

Signed-off-by: Christian Tzolov <[email protected]>
Signed-off-by: Christian Tzolov <[email protected]>
Signed-off-by: Christian Tzolov <[email protected]>
Signed-off-by: Christian Tzolov <[email protected]>
Signed-off-by: Christian Tzolov <[email protected]>
- Implement StructuredOutputChatOptions interface in GoogleGenAiChatOptions
- Add responseSchema field and related getter/setter methods
- Add outputSchema bridge methods for unified Spring AI API
- Update GoogleGenAiChatModel to handle responseSchema configuration
- Add integration tests for both native and unified structured output APIs
- Include tests for ChatClient with native structured output advisor
- Update VertexAI Gemini tests with consistent naming and structured output support

Signed-off-by: Christian Tzolov <[email protected]>
@tzolov tzolov force-pushed the native-structured-output branch from 569ac6f to d3bad12 Compare November 20, 2025 17:25
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.

Add Anthropic Claude Structured Output support Add support for native GenAI response schema instead of instruction injection

3 participants