- Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Expected Behavior
When handling a ToolExecutionException, if the exception message is null
or an empty string
, the system should still return a meaningful fallback message so the LLM can properly recognize the error condition.
For example:
String message = exception.getMessage(); if (message == null || message.isBlank()) { message = "Exception occurred in tool: " + exception.getToolDefinition().name(); }
Current Behavior
Currently, when a RuntimeException
is created with a null
or blank
message, the process method returns exception.getMessage()
as-is.
This results in tool results being null
or "", which then get recorded in the chat history. Downstream LLM implementations often misinterpret or fail when they encounter such empty messages.
Context
In practice, empty strings are recorded in the chat history, making it harder for the LLM to understand or recover from the error.
Providing a fallback message (e.g. "Exception occurred in tool: [ToolName] (ToolExecutionException)") ensures the LLM has enough context to handle the failure gracefully.
This change improves robustness and observability without altering behavior when a non-empty message is present.
I am preparing a PR to implement this improvement.