Skip to content

[google gen ai, vertexai] Important fixes (GoogleGenAiChatModel thoughts, JsonSchemaConverter nullable types and defs)#5211

Closed
viacheslav-dobrynin wants to merge 8 commits into
spring-projects:mainfrom
viacheslav-dobrynin:handle_nullable_fields
Closed

[google gen ai, vertexai] Important fixes (GoogleGenAiChatModel thoughts, JsonSchemaConverter nullable types and defs)#5211
viacheslav-dobrynin wants to merge 8 commits into
spring-projects:mainfrom
viacheslav-dobrynin:handle_nullable_fields

Conversation

@viacheslav-dobrynin

@viacheslav-dobrynin viacheslav-dobrynin commented Jan 9, 2026

Copy link
Copy Markdown
Contributor

This PR includes several fixes:

  1. GoogleGenAiChatModel:
  • Mark internal “thoughts” in the message metadata. For Gemini 3* models we must set include-thoughts to true to enable thought_signatures, but the model also return them in the visible output.
  • Prevent missing thought_signature errors in streaming tool calls.
  1. JsonSchemaConverter: Disallow $defs / $ref. Google’s supported OpenAPI schema subset does not support definitions and references, so forbidding them avoids unexpected behavior.

  2. JsonSchemaConverter: Handle nullable types via nullable: true. Google’s OpenAPI schema (3.0.3) does not support nullable union types (e.g., ["null", T]), so we convert them to nullable: true.

  3. vertexai.JsonSchemaConverterTests: Add missing tests by porting them from genai.JsonSchemaConverterTests.

  4. MessageAggregator: Add separated thoughts and output metadata to the aggregated message.

@harry-yoo-eb

harry-yoo-eb commented Jan 15, 2026

Copy link
Copy Markdown

Is there any chance or timeline to support thought_signatures in VertexAiGeminiChatModel.java ?

@viacheslav-dobrynin

Copy link
Copy Markdown
Contributor Author

@ilayaperumalg, I can break this PR into multiple smaller PRs if that would be more convenient for review and delivery.

Signed-off-by: Viacheslav Dobrynin <w.v.dobr@gmail.com>

# Conflicts:
#	models/spring-ai-google-genai/src/main/java/org/springframework/ai/google/genai/schema/JsonSchemaConverter.java
#	models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/schema/JsonSchemaConverter.java
Signed-off-by: Viacheslav Dobrynin <w.v.dobr@gmail.com>
Signed-off-by: Viacheslav Dobrynin <w.v.dobr@gmail.com>
Signed-off-by: Viacheslav Dobrynin <w.v.dobr@gmail.com>
Signed-off-by: Viacheslav Dobrynin <w.v.dobr@gmail.com>
Signed-off-by: Viacheslav Dobrynin <w.v.dobr@gmail.com>
- Change switchMap to concatMap to prevent dropping streaming chunks
- Ensure thought_signatures from all chunks are collected before
  building conversation history for subsequent tool calling steps

Signed-off-by: Viacheslav Dobrynin <w.v.dobr@gmail.com>
@cho-thinkfree-com

Copy link
Copy Markdown
Contributor

I believe this PR resolves the following issue:
#4911

To fix the thought_signature problem mentioned in #4911, I copied some of the GoogleGenAiChatModel code and the MessageAggregator provided in this Pull Request. I can confirm that it works perfectly without any issues in Spring AI 1.1.2.
(Note: I haven't verified the changes related to the JsonSchemaConverter nullable types and defs.)

ericbottard pushed a commit that referenced this pull request Mar 12, 2026
- filter thoughts from model output
- validate that input json schema doesn't contain $defs since google doesn't support it
  Details: https://ai.google.dev/gemini-api/docs/structured-output?example=recipe#type-specific_properties, https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/control-generated-output#fields
- don't skip thought but mark with flag in metadata
- prevent missing thought_signature errors in streaming tool calls
  - Change switchMap to concatMap to prevent dropping streaming chunks
  - Ensure thought_signatures from all chunks are collected before
  building conversation history for subsequent tool calling steps

Signed-off-by: Viacheslav Dobrynin <w.v.dobr@gmail.com>

Original PR: #5211
@ericbottard

Copy link
Copy Markdown
Member

Thanks for your contribution @viacheslav-dobrynin !

Merged on main as f7ccb10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working google genai vertex

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants