Class GuardrailRefusalException

All Implemented Interfaces:
Serializable

public class GuardrailRefusalException extends ContentFilteredException
Thrown when an answer of the model is asked for as an entity and a guardrail refused the turn instead.

A refusal is a reply in the guardrail's own words, not the structured output that was requested, so there is nothing to convert. Converting it anyway would fail as malformed output and hide what happened. The exception carries the response, with the refusal and the context the guardrail left, so that the caller can tell the person why there is no answer.

The response is not serializable. A serialized exception keeps the text of the refusal and leaves the response behind.

A refusal is a response that a filter stopped, so the exception is a ContentFilteredException: a caller that handles both the refusal of a guardrail and the safety stop of a provider catches that one type. Unlike a response that a provider stopped, a refusal is never converted, as it is not what the model said.

Since:
2.1.0
Author:
Christian Tzolov
See Also:
  • Constructor Details

    • GuardrailRefusalException

      public GuardrailRefusalException(ChatClientResponse chatClientResponse)
      Creates the exception for a refused turn.
      Parameters:
      chatClientResponse - the response that carries the refusal
  • Method Details

    • getRefusal

      public @Nullable String getRefusal()
      What the guardrail said in place of an answer. It is also the text of the exception.
      Returns:
      the text of the refusal, or null when it has none