Skip to content

Issue 3884 Improve tool parameter conversion error messages #3970

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

wilocu
Copy link

@wilocu wilocu commented Aug 1, 2025

Summary

This PR enhances error handling for tool parameter type conversion failures by providing detailed, actionable error messages when the model returns
values that cannot be converted to expected parameter types (e.g., empty strings for numeric parameters).

Changes

  1. New ToolParameterConversionException Class
  • Extends ToolExecutionException to provide parameter-specific context
  • Includes parameter name, expected type, actual value, and helpful suggestions
  • Provides different guidance for numeric vs non-numeric type failures
  1. Enhanced MethodToolCallback
  • Catches NumberFormatException and IllegalStateException during parameter conversion
  • Wraps conversion errors with ToolParameterConversionException including parameter context
  • Maintains backward compatibility through exception hierarchy
  1. Improved JsonParser.toTypedObject()
  • Better error messages for all numeric type conversions (Byte, Short, Integer, Long, Float, Double)
  • Enhanced enum conversion error messages with available options
  • Filters redundant original error messages for cleaner output

Error Message Examples

Before:
java.lang.NumberFormatException: null

After:
Tool parameter conversion failed for parameter 'userId' in tool 'getUserData':
Expected type: Long, but received: "" (empty string)
Suggestion: Ensure your prompt clearly specifies that numeric parameters should contain valid numbers, not empty strings.
Consider making the parameter optional or providing a default value in your tool description.

Testing

  • Added comprehensive test coverage for new exception types
  • Validated error message quality and content
  • Ensured no regressions in existing functionality
  • All 35 JsonParserTests pass, confirming backward compatibility

Signed-off-by: Mattia Pasetto [email protected]

I am still pretty new to contributions, please double check and let me know of any errors.

Signed-off-by: Mattia Pasetto <[email protected]>
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.

1 participant