Skip to content

GH-3884: Throw clear exception when tool parameter receives empty string from model#6018

Open
suryateja-g13 wants to merge 1 commit into
spring-projects:mainfrom
suryateja-g13:GH-3884-empty-string-tool-param
Open

GH-3884: Throw clear exception when tool parameter receives empty string from model#6018
suryateja-g13 wants to merge 1 commit into
spring-projects:mainfrom
suryateja-g13:GH-3884-empty-string-tool-param

Conversation

@suryateja-g13
Copy link
Copy Markdown

What

When a model returns an empty string for a numeric tool parameter (e.g. Long, Integer, Double, Short), JsonParser.toTypedObject() previously threw a cryptic NumberFormatException with no context about what went wrong.

Why

The fix adds an early blank-string guard in toTypedObject() that throws IllegalArgumentException with a clear message indicating the expected type. Empty strings are still allowed for String type parameters. Blank strings (whitespace-only) are also caught since they cause the same downstream failure.

Changes

  • JsonParser.toTypedObject() — added blank string guard before numeric conversion
  • JsonParserTests — added 6 new tests covering empty/blank string rejection for numeric types, and empty string passthrough for String type

Fixes GH-3884 (#3884)

…eives blank string from model

When a model returns a blank or empty string for a numeric tool parameter
(Byte, Short, Integer, Long, Float, Double), JsonParser.toTypedObject()
previously threw a cryptic NumberFormatException. Now throws
IllegalArgumentException with a clear message indicating the expected type.

Boolean and enum types are excluded from the guard: Boolean.parseBoolean("")
returns false by contract, and enum conversion already throws a clear
IllegalArgumentException for unrecognised values.

Fixes spring-projectsGH-3884 (spring-projects#3884)

Signed-off-by: Gorre Surya <suryateja.g13@gmail.com>
@suryateja-g13 suryateja-g13 force-pushed the GH-3884-empty-string-tool-param branch from 883894a to 6b38c6e Compare May 13, 2026 03:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant