Class ToolInputGuardrailException

All Implemented Interfaces:
Serializable

@Experimental public final class ToolInputGuardrailException extends GuardrailException
Exception thrown when a fatal ToolInputGuardrail failure aborts the AI service invocation. It is thrown before a tool is executed, so the tool was not executed.

This class is not intended to be thrown within guardrail implementations. It is for the framework only. It is ok to catch it.

Since:
1.25.0
See Also:
  • Constructor Details

    • ToolInputGuardrailException

      public ToolInputGuardrailException(String message)
      Creates the exception with a message.
      Parameters:
      message - the message
    • ToolInputGuardrailException

      public ToolInputGuardrailException(String message, @Nullable Throwable cause)
      Creates the exception with a message and a cause.
      Parameters:
      message - the message
      cause - the cause, or null when there is none
  • Method Details

    • toolExecutionRequest

      public Optional<ToolExecutionRequest> toolExecutionRequest()
      Gets the tool call that the failure stopped: its id, the name of the tool and its arguments, as the failing guardrail validated them: after the rewrites of the guardrails that ran before it (the arguments the LLM sent if none of them rewrote them). The tool was not executed, but the framework reports the rejected call with these arguments, as it does for a non-fatal failure (see ToolInputGuardrailResult.rewrittenArguments()).

      With several tool calls in one response of the LLM, or a guardrail that applies to every tool, it tells which call failed. The message names the tool, but not the arguments, which can hold user data.

      Returns:
      the tool call, or empty if the exception was not thrown by a ToolInputGuardrailExecutor