Skip to content

feat(tools): Add configurable exception handling for tool execution #3264

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

Closed

Conversation

tzolov
Copy link
Contributor

@tzolov tzolov commented May 20, 2025

Adds a new configuration property spring.ai.tools.throw-exception-on-error that controls how tool execution errors are handled:

  • When false (default): errors are converted to messages and sent back to the AI model
  • When true: errors are thrown as exceptions for the caller to handle

The implementation:

  • Adds the property to ToolCallingProperties
  • Updates ToolCallingAutoConfiguration to use the property
  • Improves error handling in MCP tool callbacks to use ToolExecutionException
  • Adds tests to verify both behaviors
  • Updates documentation with the new property

Adds a new configuration property `spring.ai.tools.throw-exception-on-error` that controls how tool execution errors are handled:
- When false (default): errors are converted to messages and sent back to the AI model
- When true: errors are thrown as exceptions for the caller to handle

The implementation:
- Adds the property to ToolCallingProperties
- Updates ToolCallingAutoConfiguration to use the property
- Improves error handling in MCP tool callbacks to use ToolExecutionException
- Adds tests to verify both behaviors
- Updates documentation with the new property

Signed-off-by: Christian Tzolov <[email protected]>
@ilayaperumalg
Copy link
Member

LGTM. In the ToolCallingAutoConfiguration, we can perhaps use the builder method in DefaultToolExecutionExceptionProcessor to set the alwaysThrow boolean value instead of setting at the constructor level. But this can be addressed separately as we may also need to decide whether to deprecate the existing public constructor for DefaultToolExecutionExceptionProcessor. Merging.

@ilayaperumalg
Copy link
Member

Rebased and merged as 6f61fee.

@ilayaperumalg
Copy link
Member

Back ported to 1.0.x via 3068c04

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants