Class ToolErrorVisibleToLlmException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
dev.langchain4j.exception.ToolErrorVisibleToLlmException
All Implemented Interfaces:
ToolErrorVisibleToLlm, Serializable

public class ToolErrorVisibleToLlmException extends RuntimeException implements ToolErrorVisibleToLlm
A ready-made ToolErrorVisibleToLlm exception: throw it from a @Tool method when you want to tell the LLM what went wrong without declaring an exception class of your own.

Usually created via ToolErrorVisibleToLlm.from(String) or ToolErrorVisibleToLlm.from(String, Throwable).

Since:
1.21.0
See Also:
  • Constructor Details

    • ToolErrorVisibleToLlmException

      public ToolErrorVisibleToLlmException(String message)
    • ToolErrorVisibleToLlmException

      public ToolErrorVisibleToLlmException(String message, Throwable cause)
  • Method Details

    • messageForLlm

      public String messageForLlm()
      Description copied from interface: ToolErrorVisibleToLlm
      The 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:
      messageForLlm in interface ToolErrorVisibleToLlm