Class LlmVisibleToolExecutionException
- All Implemented Interfaces:
ToolErrorVisibleToLlm, Serializable
- Direct Known Subclasses:
McpApplicationErrorException
ToolExecutionException whose message is written for the LLM, so it implements
ToolErrorVisibleToLlm: error handlers that honor that interface send the message to the LLM
instead of failing the AI Service invocation.
It is thrown by tools that LangChain4j provides (for example, skills and tool search) when the LLM can do something about the failure, typically when it called the tool with a missing or invalid argument.
To tell the LLM about a failure in your own @Tool method, throw
ToolErrorVisibleToLlm.from(String) or your own exception implementing ToolErrorVisibleToLlm.
- Since:
- 1.21.0
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionLlmVisibleToolExecutionException(String message) LlmVisibleToolExecutionException(String message, Throwable cause) -
Method Summary
Modifier and TypeMethodDescriptionThe text that is sent to the LLM as the result of the failed tool execution.Methods inherited from class ToolExecutionException
errorCodeMethods inherited from class Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
LlmVisibleToolExecutionException
- Parameters:
message- the text to send to the LLM, written for the LLM. Must not be blank.
-
LlmVisibleToolExecutionException
-
-
Method Details
-
messageForLlm
Description copied from interface:ToolErrorVisibleToLlmThe text that is sent to the LLM as the result of the failed tool execution.Write it for the LLM, not for a log file: say what went wrong and, when it helps, what the LLM could do about it. Do not pass the message of another exception through (for example
return cause.getMessage()): such messages are written for developers and often contain internal details that should not reach the LLM provider.Must not be blank. A blank text is ignored (and a warning is logged), and the exception is treated as if it did not implement this interface: a handler that fails the invocation fails it, and a handler that sends the message of the exception to the LLM sends that instead.
- Specified by:
messageForLlmin interfaceToolErrorVisibleToLlm
-