Package dev.langchain4j.guardrail
Interface GuardrailResult<GR extends GuardrailResult<GR>>
- Type Parameters:
GR
- The type of guardrail result to expect
- All Known Implementing Classes:
InputGuardrailResult
,OutputGuardrailResult
public sealed interface GuardrailResult<GR extends GuardrailResult<GR>>
permits InputGuardrailResult, OutputGuardrailResult
The result of the validation of an interaction between a user and the LLM.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
The message and the cause of the failure of a single validation.static enum
The possible results of a guardrails validation. -
Method Summary
Modifier and TypeMethodDescriptiondefault String
asString()
<F extends GuardrailResult.Failure>
List<F> failures()
default Throwable
Gets the exception from the first failuredefault boolean
Whether or not the result is successful, but the result was re-written, potentially due to re-promptingdefault boolean
isFatal()
Whether or not the result is considered fataldefault boolean
Whether or not the result is considered successfulresult()
The result of the guardrailThe message of the successful resultdefault GR
validatedBy
(Class<? extends Guardrail> guardrailClass) TheGuardrail
class which performed this validation
-
Method Details
-
result
GuardrailResult.Result result()The result of the guardrail -
failures
- Returns:
- The list of failures eventually resulting from a set of validations.
-
successfulText
String successfulText()The message of the successful result -
hasRewrittenResult
default boolean hasRewrittenResult()Whether or not the result is successful, but the result was re-written, potentially due to re-prompting -
isFatal
default boolean isFatal()Whether or not the result is considered fatal -
isSuccess
default boolean isSuccess()Whether or not the result is considered successful -
getFirstFailureException
Gets the exception from the first failure -
validatedBy
TheGuardrail
class which performed this validation -
asString
-