spring-projects / spring-projects/spring-ai

When the Tool parameter is an empty string, a type conversion error occurs, reporting java.lang.NumberFormatException

Open
#3,884 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug tool calling
Dominant language
Java
Stars
9.5k
Forks
2.9k
Avg merge
1d 7h
Merged PRs (30d)
6

Description

Please do a quick search on GitHub issues first, there might be already a duplicate issue for the one you are about to create.
If the bug is trivial, just go ahead and create the issue. Otherwise, please take a few moments and fill in the following sections:

Bug description
A clear and concise description of what the bug is about.

A type conversion error occurs when the Tool parameter is an empty string, throwing java.lang.NumberFormatException.

  • The parameter type of the tool is Long.
  • The Tool parameter responded by the LLM is an empty string.
java.lang.NumberFormatException
	at java.base/java.math.BigDecimal.<init>([BigDecimal.java:692](http://bigdecimal.java:692/))
	at java.base/java.math.BigDecimal.<init>([BigDecimal.java:471](http://bigdecimal.java:471/))
	at java.base/java.math.BigDecimal.<init>([BigDecimal.java:900](http://bigdecimal.java:900/))
	at [org.springframework.ai](http://org.springframework.ai/).util.json.JsonParser.toTypedObject([JsonParser.java:139](http://jsonparser.java:139/))
	at [org.springframework.ai](http://org.springframework.ai/).tool.method.MethodToolCallback.buildTypedArgument([MethodToolCallback.java:150](http://methodtoolcallback.java:150/))
	at [org.springframework.ai](http://org.springframework.ai/).tool.method.MethodToolCallback.lambda$buildMethodArguments$1([MethodToolCallback.java:139](http://methodtoolcallback.java:139/))
	at java.base/[java.util.stream](http://java.util.stream/).ReferencePipeline$3$1.accept([ReferencePipeline.java:197](http://referencepipeline.java:197/))
	at java.base/java.util.Spliterators$ArraySpliterator.forEachRemaining([Spliterators.java:992](http://spliterators.java:992/))
	at java.base/[java.util.stream](http://java.util.stream/).AbstractPipeline.copyInto([AbstractPipeline.java:509](http://abstractpipeline.java:509/))
	at java.base/[java.util.stream](http://java.util.stream/).AbstractPipeline.wrapAndCopyInto([AbstractPipeline.java:499](http://abstractpipeline.java:499/))
	at java.base/[java.util.stream](http://java.util.stream/).AbstractPipeline.evaluate([AbstractPipeline.java:575](http://abstractpipeline.java:575/))
	at java.base/[java.util.stream](http://java.util.stream/).AbstractPipeline.evaluateToArrayNode([AbstractPipeline.java:260](http://abstractpipeline.java:260/))
	at java.base/[java.util.stream](http://java.util.stream/).ReferencePipeline.toArray([ReferencePipeline.java:616](http://referencepipeline.java:616/))
	at java.base/[java.util.stream](http://java.util.stream/).ReferencePipeline.toArray([ReferencePipeline.java:622](http://referencepipeline.java:622/))
	at [org.springframework.ai](http://org.springframework.ai/).tool.method.MethodToolCallback.buildMethodArguments([MethodToolCallback.java:140](http://methodtoolcallback.java:140/))
	at [org.springframework.ai.tool.method.MethodToolCallback.call](http://org.springframework.ai.tool.method.methodtoolcallback.call/)([MethodToolCallback.java:107](http://methodtoolcallback.java:107/))

Environment
Please provide as many details as possible: Spring AI version, Java version, which vector store you use if any, etc

  • Spring AI 1.0.0

Steps to reproduce
Steps to reproduce the issue.

Expected behavior
A clear and concise description of what you expected to happen.

Should an empty string be converted to null? Of course, that's a matter for discussion.

Minimal Complete Reproducible example
Please provide a failing test or a minimal complete verifiable example that reproduces the issue.
Bug reports that are reproducible will take priority in resolution over reports that are not reproducible.

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

Start by reading org.springframework.ai.util.json.JsonParser.toTypedObject at JsonParser.java:139 and the argument conversion flow in MethodToolCallback.java:107-150. Reproduce the empty-string Tool parameter with a Long type if possible, then establish and verify the agreed behavior for that input without the NumberFormatException.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring
Domain
ai, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.