Context
The ApplyWell assistant crashes during contextual follow-up questions when Gemini invokes searchApplications without a text query.
Observed flow:
- User asks for aggregate data, e.g.
quantas vagas eu já me inscrevi na CWI?
- Assistant answers correctly using stats.
- User follows up with
Alguma delas eu fiz entrevista?
- Gemini invokes
searchApplications with structured context/filters but without query.
AssistantApplicationQueryService.requiredQuery() throws IllegalArgumentException("query is required").
- Spring AI
GoogleGenAiChatModel tries to parse the plain-text tool error as JSON and crashes in parseJsonToMap() / messageToGeminiParts().
- Frontend receives the generic
The assistant is temporarily unavailable. state.
Evidence
Backend logs around 2026-09-15 21:49 BRT:
java.lang.RuntimeException: Failed to parse JSON: query is required
at org.springframework.ai.google.genai.GoogleGenAiChatModel.parseJsonToMap(...)
at org.springframework.ai.google.genai.GoogleGenAiChatModel.messageToGeminiParts(...)
Caused by: com.fasterxml.jackson.core.JsonParseException:
Unrecognized token 'query': was expecting JSON String, Number, Array, Object or token 'null', 'true' or 'false'
Relevant code:
AssistantTools.searchApplications(SearchInput input)
AssistantApplicationQueryService.search(...)
AssistantApplicationQueryService.requiredQuery(...)
Root causes
1. searchApplications requires query even when structured filters are sufficient
The tool exposes structured fields such as organization, status, platform, and date range, but the service always requires a non-empty query.
This makes contextual follow-ups fragile because the model may correctly preserve structured context without repeating the original search text.
2. Non-JSON tool failures are unsafe with Spring AI Google GenAI
Spring AI currently has an upstream issue where GoogleGenAiChatModel assumes tool responses are JSON and crashes on plain text:
Until that is fixed upstream, tool outputs/errors sent back to Gemini should be structured JSON-safe payloads.
Expected behavior
A contextual question such as:
User: quantas vagas eu já me inscrevi na CWI?
Assistant: Você já se inscreveu em 5 vagas na CWI.
User: Alguma delas eu fiz entrevista?
must complete successfully without requiring the model to repeat CWI as a free-text query.
Acceptance criteria
Notes
Prefer fixing the tool contract and error serialization rather than forcing the prompt to always fabricate/repeat a text query. The tool schema should reflect what the backend actually supports, otherwise the model gets blamed for stepping on a rake we left in the hallway.
Context
The ApplyWell assistant crashes during contextual follow-up questions when Gemini invokes
searchApplicationswithout a textquery.Observed flow:
quantas vagas eu já me inscrevi na CWI?Alguma delas eu fiz entrevista?searchApplicationswith structured context/filters but withoutquery.AssistantApplicationQueryService.requiredQuery()throwsIllegalArgumentException("query is required").GoogleGenAiChatModeltries to parse the plain-text tool error as JSON and crashes inparseJsonToMap()/messageToGeminiParts().The assistant is temporarily unavailable.state.Evidence
Backend logs around 2026-09-15 21:49 BRT:
Relevant code:
AssistantTools.searchApplications(SearchInput input)AssistantApplicationQueryService.search(...)AssistantApplicationQueryService.requiredQuery(...)Root causes
1.
searchApplicationsrequiresqueryeven when structured filters are sufficientThe tool exposes structured fields such as
organization,status,platform, and date range, but the service always requires a non-emptyquery.This makes contextual follow-ups fragile because the model may correctly preserve structured context without repeating the original search text.
2. Non-JSON tool failures are unsafe with Spring AI Google GenAI
Spring AI currently has an upstream issue where
GoogleGenAiChatModelassumes tool responses are JSON and crashes on plain text:Until that is fixed upstream, tool outputs/errors sent back to Gemini should be structured JSON-safe payloads.
Expected behavior
A contextual question such as:
must complete successfully without requiring the model to repeat
CWIas a free-textquery.Acceptance criteria
searchApplicationsaccepts a null/blankquerywhen at least one structured filter is present.query == null.Alguma delas eu fiz entrevista?.GoogleGenAiChatModel.Notes
Prefer fixing the tool contract and error serialization rather than forcing the prompt to always fabricate/repeat a text query. The tool schema should reflect what the backend actually supports, otherwise the model gets blamed for stepping on a rake we left in the hallway.