Skip to content

Add validation for Tool annotation names #3887

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 2 commits into
base: main
Choose a base branch
from

Conversation

academey
Copy link

Add warning-based validation for tool names in ToolUtils to help users avoid compatibility issues with certain LLMs.

What this PR does:

  • Adds validateToolName() method in ToolUtils that logs warnings for non-recommended tool names
  • Tool names are recommended to contain only alphanumeric characters, underscores, hyphens, and dots
  • Updates @tool annotation JavaDoc with naming recommendations and examples
  • Adds comprehensive unit tests including edge cases and unicode support

Implementation details:

  • Uses SLF4J logger for warning messages (consistent with project patterns)
  • Pre-compiled regex pattern for performance
  • Does NOT throw exceptions - maintains backward compatibility
  • Allows unicode characters for international use cases

Example warning:

Tool name 'invalid tool name' may not be compatible with some LLMs (e.g., OpenAI). Consider using only alphanumeric characters, underscores, hyphens, and dots.

Fixes #3832

Signed-off-by: Hyunjoon Park academey@gmail.com

academey added 2 commits July 18, 2025 18:46
- Add regex pattern validation for tool names in ToolUtils
- Tool names can only contain alphanumeric characters, underscores, hyphens, and dots
- Add comprehensive unit tests for tool name validation
- Update @tool annotation documentation with naming constraints
- Throw IllegalArgumentException for invalid tool names with clear error message

This prevents runtime failures when LLMs (like GPT 4.1-mini) encounter tool names
with spaces or special characters that they cannot process.

Fixes spring-projects#3832

Signed-off-by: Hyunjoon Park <academey@gmail.com>
Based on feedback, the validation has been changed from throwing an exception
to logging a warning. This approach is more flexible as the Tool annotation
is generic and not specific to any particular LLM.

Changes:
- Modified ToolUtils to log warnings instead of throwing exceptions
- Updated Tool annotation JavaDoc to recommend naming conventions
- Adjusted tests to verify tool names are returned (no exceptions thrown)
- Added test for unicode characters to support non-English contexts

The warning message guides users toward compatible naming while allowing
flexibility for different LLMs and use cases.

Fixes spring-projects#3832

Signed-off-by: Hyunjoon Park <academey@gmail.com>
@ilayaperumalg ilayaperumalg added this to the 1.1.x milestone Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tool annotation name validation
2 participants