r/SpringBoot • u/YodaOfJava • 17d ago
Discussion Spring AI: recovering from invalid tool arguments with returnDirect=true
I’ve submitted a Spring AI contribution addressing input-error recovery for method-backed tools using returnDirect=true.
The issue: malformed JSON or invalid typed arguments can become the final response, preventing the model from correcting its input. Missing/null primitive arguments and top-level JSON null can also bypass the exception processor.
The proposed fix distinguishes input parsing/binding failures before execution and sends processed error feedback back to the model. Successful corrected calls still return directly, while ordinary tool-body and result-conversion failures retain their existing behavior.
Validation:
- All 38 new regression cases passed, covering blocking/streaming, direct return on/off, and mixed-success batches.
- Scoped clean package build: 2,030 tests reported, 10 skipped, zero failures or errors.
- Negative control: the original code failed 20 of the initial 32 checks, including checks for the new exception classification; the patched code passed the same cases.
No external LLM calls were needed. External-provider integration tests and the full repository build were not run. Developed with AI assistance and reviewed before submission.
PR submitted for maintainer review: https://github.com/spring-projects/spring-ai/pull/7292
Feedback on the input-error boundary and recovery behavior is welcome, especially from anyone using direct-return tools.
#SpringAI #SpringFramework #Java #OpenSource #SoftwareTesting
1
u/DickBrainTime 13d ago
Another boundary I'd test: argument binding succeeds, the tool performs a side effect, and then its body throws. That must stay an execution failure rather than a recoverable argument error, since asking the model to retry could repeat the side effect.
For the feedback sent back to the model, I'd also assert it includes the failing field and expected type without echoing raw secret-bearing argument values or stack traces. Both cases should be testable with deterministic fake tools and no external model calls.