spring-projects / spring-projects/spring-ai
Tool Calling, `String` inputType method with json-style String LLM response causing Jackson parse exception.
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
I have a Tool (func as tool) defined like this:
class PlanningTool implements Function<String, Result> {
public Result apply (String input) {
//
}
}
Declare and register FunctionToolCallback to ChatClient like this:
FunctionToolCallback
.builder(name, new PlanningTool())
.description(description)
.inputSchema(PARAMETERS)
.inputType(String.class)
.build();
If the LLM returns json style input String like blow:
Jackson parser will produce the following exception:
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)
at [Source: REDACTED (`StreamReadFeature.INCLUDE_SOURCE_IN_LOCATION` disabled); line: 1, column: 1]
at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59) ~[jackson-databind-2.18.1.jar:2.18.1]
at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1767) ~[jackson-databind-2.18.1.jar:2.18.1]
at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1541) ~[jackson-databind-2.18.1.jar:2.18.1]
Some code like this should solve this issue:
I request;
if (toolInputType == String.class) {
request = (I) toolInput;
} else{
request = JsonParser.fromJson(toolInput, toolInputType);
}
Environment
1.0.0-M6
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
The issue names no source file or test; start at FunctionToolCallback.builder(...).inputType(String.class) and trace the Jackson conversion of tool input before PlanningTool.apply(String input). Done means JSON-style input reaches String tools without the reported MismatchedInputException while non-String tool inputs retain their existing deserialization behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- ai, backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100