Class GuardrailRefusalException
- All Implemented Interfaces:
Serializable
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 Summary
ConstructorsConstructorDescriptionGuardrailRefusalException(ChatClientResponse chatClientResponse) Creates the exception for a refused turn. -
Method Summary
Modifier and TypeMethodDescription@Nullable StringWhat the guardrail said in place of an answer.Methods inherited from class org.springframework.ai.chat.client.ContentFilteredException
getChatClientResponse, getFinishReason, getTextMethods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
-
Constructor Details
-
GuardrailRefusalException
Creates the exception for a refused turn.- Parameters:
chatClientResponse- the response that carries the refusal
-
-
Method Details
-
getRefusal
What the guardrail said in place of an answer. It is also thetextof the exception.- Returns:
- the text of the refusal, or
nullwhen it has none
-