Accept plain text tool results in GoogleGenAiChatModel - #6907
Open
harrisleesh wants to merge 1 commit into
Open
Conversation
Tool response payloads were converted with a strict JSON parse, so any
plain-text tool result - such as the tool call limit breach message
produced with `on-limit-exceeded=RETURN_ERROR_RESPONSE` - made the
next model call fail with "Failed to parse JSON" instead of letting
the model see the text.
Wrap non-JSON tool response text as {"result": <text>}, the same way
non-object JSON values are already wrapped, so every tool result is
accepted by the Gemini API.
Fixes spring-projects#6902
Signed-off-by: seonghun lee <harrisleesh@gmail.com>
harrisleesh
force-pushed
the
gh-6902-genai-tool-response
branch
from
September 3, 2026 12:28
f781427 to
9a7f001
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
GoogleGenAiChatModelconverts every tool response payload with a strict JSON parse. Plain text that is not valid JSON - most notably the tool call limit breach message produced withspring.ai.tools.limits.on-limit-exceeded=RETURN_ERROR_RESPONSE, but also any customToolCallbackreturning raw text - makes the next model call fail withFailed to parse JSON: ...instead of letting Gemini see the message. This defeats whatRETURN_ERROR_RESPONSEpromises.This implements fix 2 proposed in the issue: since the model already wraps non-object JSON values as
{"result": value}, non-JSON text is now wrapped the same way ({"result": "<text>"}), which makes every tool result Gemini-safe regardless of what produced it. Function call arguments coming from the model keep the strict parse.Changes
toolResponseToMapmethod that falls back to wrapping the raw text as{"result": <text>}when it is not valid JSON.Fixes #6902