Package dev.langchain4j.guardrail
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 ClassesModifier and TypeClassDescriptionstatic final class
Represents an output guardrail failureNested classes/interfaces inherited from interface dev.langchain4j.guardrail.GuardrailResult
GuardrailResult.Result
-
Method Summary
Modifier and TypeMethodDescriptionBlock all retries for this resultboolean
static OutputGuardrailResult
failure
(List<OutputGuardrailResult.Failure> failures) Produces a non-fatal failure<F extends GuardrailResult.Failure>
List<F> failures()
Gets the reprompt messageint
hashCode()
boolean
Whether or not the guardrail is forcing a repromptboolean
isRetry()
Whether or not the guardrail is forcing a retry<T> T
response
(OutputGuardrailRequest request) Gets the response computed from the combination of the originalChatResponse
in theOutputGuardrailRequest
and this resultresult()
The result of the guardrailstatic OutputGuardrailResult
success()
Gets a successful output guardrail resultThe message of the successful resultstatic OutputGuardrailResult
successWith
(String successfulText) Produces a successful result with specific success textstatic OutputGuardrailResult
successWith
(String successfulText, Object successfulResult) Produces a non-fatal failuretoString()
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface dev.langchain4j.guardrail.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 non-fatal failure- 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.
-
failure
Produces a non-fatal failure- Parameters:
failures
- A list ofOutputGuardrailResult.Failure
s- 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
Gets the reprompt message -
toString
-
equals
-
hashCode
public int hashCode() -
response
Gets the response computed from the combination of the originalChatResponse
in theOutputGuardrailRequest
and 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
ChatResponse
in theOutputGuardrailRequest
and this result
-
result
Description copied from interface:GuardrailResult
The result of the guardrail- Specified by:
result
in interfaceGuardrailResult<OutputGuardrailResult>
-
failures
- Specified by:
failures
in interfaceGuardrailResult<OutputGuardrailResult>
- Returns:
- The list of failures eventually resulting from a set of validations.
-
successfulText
Description copied from interface:GuardrailResult
The message of the successful result- Specified by:
successfulText
in interfaceGuardrailResult<OutputGuardrailResult>
-
successfulResult
-