spring-projects / spring-projects/spring-ai

Tool Calling, `String` inputType method with json-style String LLM response causing Jackson parse exception.

Open
#2,497 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

status: waiting-for-triage
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:

Image

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.