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
  • Method Details

    • success

      public static OutputGuardrailResult success()
      Gets a successful output guardrail result
    • successWith

      public static OutputGuardrailResult successWith(String successfulText)
      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

      public static OutputGuardrailResult successWith(String successfulText, Object successfulResult)
      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.
    • successWith

      public static OutputGuardrailResult successWith(AiMessage successfulAiMessage)
      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 non-fatal failure
      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

      public static OutputGuardrailResult failure(List<OutputGuardrailResult.Failure> failures)
      Produces a non-fatal failure
      Parameters:
      failures - A list of OutputGuardrailResult.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

      public OutputGuardrailResult blockRetry()
      Block all retries for this result
    • getReprompt

      public Optional<String> getReprompt()
      Gets the reprompt message
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • response

      public <T> T response(OutputGuardrailRequest request)
      Gets the response computed from the combination of the original ChatResponse in the OutputGuardrailRequest 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 the OutputGuardrailRequest and this result
    • result

      public GuardrailResult.Result result()
      Description copied from interface: GuardrailResult
      The result of the guardrail
      Specified by:
      result in interface GuardrailResult<OutputGuardrailResult>
    • failures

      public <F extends GuardrailResult.Failure> List<F> failures()
      Specified by:
      failures in interface GuardrailResult<OutputGuardrailResult>
      Returns:
      The list of failures eventually resulting from a set of validations.
    • successfulText

      public String successfulText()
      Description copied from interface: GuardrailResult
      The message of the successful result
      Specified by:
      successfulText in interface GuardrailResult<OutputGuardrailResult>
    • successfulResult

      public Object successfulResult()