Skip to content

Accept plain text tool results in GoogleGenAiChatModel - #6907

Open
harrisleesh wants to merge 1 commit into
spring-projects:mainfrom
harrisleesh:gh-6902-genai-tool-response
Open

Accept plain text tool results in GoogleGenAiChatModel#6907
harrisleesh wants to merge 1 commit into
spring-projects:mainfrom
harrisleesh:gh-6902-genai-tool-response

Conversation

@harrisleesh

@harrisleesh harrisleesh commented Sep 3, 2026

Copy link
Copy Markdown

Motivation

GoogleGenAiChatModel converts 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 with spring.ai.tools.limits.on-limit-exceeded=RETURN_ERROR_RESPONSE, but also any custom ToolCallback returning raw text - makes the next model call fail with Failed to parse JSON: ... instead of letting Gemini see the message. This defeats what RETURN_ERROR_RESPONSE promises.

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

  • Route tool response conversion through a new toolResponseToMap method that falls back to wrapping the raw text as {"result": <text>} when it is not valid JSON.
  • Added tests covering both a JSON object tool result (unchanged behavior) and a plain-text tool result (previously threw, now wrapped). The plain-text test fails without the fix.

Fixes #6902

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
harrisleesh force-pushed the gh-6902-genai-tool-response branch from f781427 to 9a7f001 Compare September 3, 2026 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool-call limit breach text is not JSON-safe: bypasses ToolExecutionExceptionProcessor, and GoogleGenAiChatModel rejects it

2 participants