Class OutputGuardrailResult
java.lang.Object
dev.langchain4j.guardrail.OutputGuardrailResult
- All Implemented Interfaces:
GuardrailResult<OutputGuardrailResult>
public final class OutputGuardrailResult
extends Object
implements GuardrailResult<OutputGuardrailResult>
The result of the validation of an
OutputGuardrail-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from interface GuardrailResult
GuardrailResult.Result -
Method Summary
Modifier and TypeMethodDescriptionBlock all retries for this resultbooleanstatic OutputGuardrailResultfailure(List<OutputGuardrailResult.Failure> failures) Produces a non-fatal failure<F extends GuardrailResult.Failure>
List<F> failures()static OutputGuardrailResultfailureWithMessageRemoval(String message) Produces a non-fatal failure that also requests removal of the violatingAiMessagefrom chat memory after the guardrail chain finishes.static OutputGuardrailResultfailureWithMessageRemoval(String message, Throwable cause) Produces a non-fatal failure that also requests removal of the violatingAiMessagefrom chat memory after the guardrail chain finishes.static OutputGuardrailResultfatalWithMessageRemoval(String message) Produces a fatal failure that also requests removal of the violatingAiMessagefrom chat memory after the guardrail chain finishes.static OutputGuardrailResultfatalWithMessageRemoval(String message, Throwable cause) Produces a fatal failure that also requests removal of the violatingAiMessagefrom chat memory after the guardrail chain finishes.Gets the reprompt messageinthashCode()booleanWhether or not the guardrail is forcing a repromptbooleanisRetry()Whether or not the guardrail is forcing a retry<T> Tresponse(OutputGuardrailRequest request) Gets the response computed from the combination of the originalChatResponsein theOutputGuardrailRequestand this resultresult()The result of the guardrailbooleanReturnstrueif any failure in this result requested removal of the violatingAiMessagefrom chat memory.static OutputGuardrailResultsuccess()Gets a successful output guardrail resultThe message of the successful resultstatic OutputGuardrailResultsuccessWith(AiMessage successfulAiMessage) Produces a successful result with specific success textstatic OutputGuardrailResultsuccessWith(AiMessage successfulAiMessage, Object successfulResult) Produces a successful result with specific AiMessage and result objectstatic OutputGuardrailResultsuccessWith(String successfulText) Produces a successful result with specific success textstatic OutputGuardrailResultsuccessWith(String successfulText, Object successfulResult) Produces a successful result with specific success text and result objecttoString()Methods inherited from interface GuardrailResult
asString, getFirstFailureException, hasRewrittenResult, isFatal, isSuccess, validatedBy
-
Method Details
-
success
Gets a successful output guardrail result -
successWith
Produces a successful result with specific success text- Parameters:
successfulText- The text of the successful result.- Returns:
- The result of a successful output guardrail validation with a specific text.
-
successWith
Produces a successful result with specific success text and result object- Parameters:
successfulText- The text of the successful result.successfulResult- The object generated by this successful result.- Returns:
- The result of a successful output guardrail validation with a specific text.
-
successWith
Produces a successful result with specific success text- Parameters:
successfulAiMessage- The AiMessage successful result.- Returns:
- The result of a successful output guardrail validation with a specific AiMessage.
-
successWith
public static OutputGuardrailResult successWith(AiMessage successfulAiMessage, Object successfulResult) Produces a successful result with specific AiMessage and result object- Parameters:
successfulAiMessage- The AiMessage successful result.successfulResult- The object generated by this successful result.- Returns:
- The result of a successful output guardrail validation with a specific AiMessage.
-
failure
Produces a non-fatal failure- Parameters:
failures- A list ofOutputGuardrailResult.Failures- Returns:
- The result of a failed output guardrail validation.
-
isRetry
public boolean isRetry()Whether or not the guardrail is forcing a retry -
isReprompt
public boolean isReprompt()Whether or not the guardrail is forcing a reprompt -
blockRetry
Block all retries for this result -
getReprompt
-
toString
-
equals
-
hashCode
-
response
Gets the response computed from the combination of the originalChatResponsein theOutputGuardrailRequestand this result- Type Parameters:
T- The type of response- Parameters:
request- The output guardrail request- Returns:
- A response computed from the combination of the original
ChatResponsein theOutputGuardrailRequestand this result
-
result
Description copied from interface:GuardrailResultThe result of the guardrail- Specified by:
resultin interfaceGuardrailResult<OutputGuardrailResult>
-
failures
- Specified by:
failuresin interfaceGuardrailResult<OutputGuardrailResult>- Returns:
- The list of failures eventually resulting from a set of validations.
-
successfulText
Description copied from interface:GuardrailResultThe message of the successful result- Specified by:
successfulTextin interfaceGuardrailResult<OutputGuardrailResult>
-
successfulResult
-
shouldRemoveViolatingMessage
public boolean shouldRemoveViolatingMessage()Returnstrueif any failure in this result requested removal of the violatingAiMessagefrom chat memory. -
failureWithMessageRemoval
Produces a non-fatal failure that also requests removal of the violatingAiMessagefrom chat memory after the guardrail chain finishes.- Parameters:
message- A message describing the failure.- Returns:
- The result of a failed output guardrail validation with memory cleanup requested.
-
failureWithMessageRemoval
Produces a non-fatal failure that also requests removal of the violatingAiMessagefrom chat memory after the guardrail chain finishes.- Parameters:
message- A message describing the failure.cause- The exception that caused this failure.- Returns:
- The result of a failed output guardrail validation with memory cleanup requested.
-
fatalWithMessageRemoval
Produces a fatal failure that also requests removal of the violatingAiMessagefrom chat memory after the guardrail chain finishes.- Parameters:
message- A message describing the failure.- Returns:
- The result of a fatally failed output guardrail validation with memory cleanup requested.
-
fatalWithMessageRemoval
Produces a fatal failure that also requests removal of the violatingAiMessagefrom chat memory after the guardrail chain finishes.- Parameters:
message- A message describing the failure.cause- The exception that caused this failure.- Returns:
- The result of a fatally failed output guardrail validation with memory cleanup requested.
-