Skip to content

ToolExecutionException does not fully cover exception scenarios, such as IllegalStateException or JsonProcessingException #4987

@internCoder

Description

@internCoder

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

Image

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

Image

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。

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions