Skip to content

bugfix: When the Tool parameter is an empty string, a type conversion error occurs #3885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lambochen
Copy link
Contributor

ref issue: #3884

Thank you for taking time to contribute this pull request!
You might have already read the contributor guide, but as a reminder, please make sure to:

  • Add a Signed-off-by line to each commit (git commit -s) per the DCO
  • Rebase your changes on the latest main branch and squash your commits
  • Add/Update unit tests as needed
  • Run a build and make sure all tests pass prior to submission

For more details, please check the contributor guide.
Thank you upfront!

… error occurs, reporting java.lang.NumberFormatException

Signed-off-by: lambochen <lambochen@yeah.net>
Signed-off-by: lambochen <lambochen@yeah.net>
@@ -141,7 +143,11 @@ public static Object toTypedObject(Object value, Class<?> type) {
if (javaType == String.class) {
return value.toString();
}
else if (javaType == Byte.class) {
if (value.toString().isEmpty()) {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The package-info for the package containing JsonParser has already been declared as @NonNullApi, so I think we should never return null under any circumstances.

I believe the current issue is essentially caused by a type mismatch between the parameters provided by the model when calling the tool and the actual parameter types expected by the tool. Therefore, I suggest we directly throw a clear exception here, including in the exception message the parameter types expected by the tool, as well as the parameter types (and values) actually provided by the model.

This would also help users improve their prompts and tool descriptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, @sunyuhan1998
Thank you for your comment.

throw a clear exception

Regarding this point, I have a different opinion.
From the perspective of this package, it indeed should not return null, as @NonNullApi has been declared. Excuse me for overlooking this when coding; I will make the adjustment.
But from the perspective of Tool Calling, parameter conversion can allow null values because the tool parameter may be optional.

In summary, I think solving this issue might be better addressed by the caller of JsonParser, i.e., the Tool Calling parameter parsing layer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parameter conversion can allow null values because the tool parameter may be optional.

I agree with your point that tool parameters should indeed allow null values.

I think perhaps we are currently facing two distinct issues:

  1. Scenarios where we should allow tool parameters to be null.
  2. Scenarios where the parameters provided by the model do not match the required parameter types of the tool.

I’m trying to express mainly relates to the second scenario. In your example, the tool expects a parameter of type Long, but the model outputs an empty string. If we extend this discussion further, suppose the tool expects a Boolean parameter, but the model provides the number 5—how should we handle such cases? Therefore, I believe it's necessary to provide users with clear feedback when such mismatches occur.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with your point, provide users with clear feedback when there is a type mismatch.

@ilayaperumalg ilayaperumalg added bug Something isn't working for: backport-to-1.0.x labels Jul 23, 2025
@ilayaperumalg ilayaperumalg added this to the 1.1.x milestone Jul 23, 2025
@lambochen lambochen marked this pull request as draft July 24, 2025 13:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working for: backport-to-1.0.x
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants