spring-projects / spring-projects/spring-ai
ToolExecutionException does not fully cover exception scenarios, such as IllegalStateException or JsonProcessingException
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.5k
- Forks
- 2.9k
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 6
Description
Bug description
There is a serialization issue before calling the model tool, which can cause the tool to not be called properly, and the DefaultToolExecutionExceptionProcessor cannot be processed through configuration
Environment
Spring AI 1.1.0
Java 21
Steps to reproduce
org.springframework.ai.tool.ToolCallback#call
org.springframework.ai.tool.method.MethodToolCallback#extractToolArguments
org.springframework.ai.util.json.JsonParser#fromJson
com.fasterxml.jackson.databind.ObjectMapper#readValue
The input text is not JSON, resulting in an IllegalStateException being thrown
java.lang.IllegalStateException: Conversion from JSON to java.util.Map<java.lang.String, java.lang.Object> failed
at org.springframework.ai.util.json.JsonParser.fromJson(JsonParser.java:97)
at org.springframework.ai.tool.method.MethodToolCallback.extractToolArguments(MethodToolCallback.java:128)
at org.springframework.ai.tool.method.MethodToolCallback.call(MethodToolCallback.java:105)
at org.springframework.ai.model.tool.DefaultToolCallingManager.lambda$executeToolCall$5(DefaultToolCallingManager.java:241)
at io.micrometer.observation.Observation.observe(Observation.java:564)
at org.springframework.ai.model.tool.DefaultToolCallingManager.executeToolCall(DefaultToolCallingManager.java:238)
at org.springframework.ai.model.tool.DefaultToolCallingManager.executeToolCalls(DefaultToolCallingManager.java:143)
at org.springframework.ai.openai.OpenAiChatModel.lambda$internalStream$9(OpenAiChatModel.java:374)
at reactor.core.publisher.FluxDeferContextual.subscribe(FluxDeferContextual.java:49)
at reactor.core.publisher.FluxSubscribeOn$SubscribeOnSubscriber.run(FluxSubscribeOn.java:194)
at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:84)
at reactor.core.scheduler.WorkerTask.call(WorkerTask.java:37)
at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:317)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: com.fasterxml.jackson.core.io.JsonEOFException: Unexpected end-of-input: expected close marker for Object (start marker at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled); line: 1, column: 1])
at [Source: REDACTED (StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION disabled); line: 4, column: 3]
at com.fasterxml.jackson.core.base.ParserMinimalBase._reportInvalidEOF(ParserMinimalBase.java:642)
at com.fasterxml.jackson.core.base.ParserBase._handleEOF(ParserBase.java:530)
at com.fasterxml.jackson.core.base.ParserBase._eofAsNextChar(ParserBase.java:547)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._skipWSOrEnd2(ReaderBasedJsonParser.java:2540)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._skipWSOrEnd(ReaderBasedJsonParser.java:2532)
at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextFieldName(ReaderBasedJsonParser.java:912)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer._readAndBindStringKeyMap(MapDeserializer.java:608)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:450)
at com.fasterxml.jackson.databind.deser.std.MapDeserializer.deserialize(MapDeserializer.java:31)
at com.fasterxml.jackson.databind.deser.DefaultDeserializationContext.readRootValue(DefaultDeserializationContext.java:342)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4971)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3887)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3870)
at org.springframework.ai.util.json.JsonParser.fromJson(JsonParser.java:94)
... 17 common frames omitted
Expected behavior
before org.springframework.ai.tool.execution.ToolExecutionExceptionProcessor#process can capture such unexpected anomalies
Minimal Complete Reproducible example
Perhaps it's related to the model's ability to process text, as there are many escape characters in my dialogue input。
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with org.springframework.ai.tool.method.MethodToolCallback#call and extractToolArguments, then trace DefaultToolCallingManager#executeToolCall and ToolExecutionExceptionProcessor#process. Reproduce the malformed JSON path described in the issue and determine whether unexpected conversion exceptions reach the configured processor; done means the reported exception scenarios are handled through that processor.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100