Class OutputGuardrailRequest

java.lang.Object
dev.langchain4j.guardrail.OutputGuardrailRequest
All Implemented Interfaces:
GuardrailRequest<OutputGuardrailRequest>

public final class OutputGuardrailRequest extends Object implements GuardrailRequest<OutputGuardrailRequest>
Represents the parameter passed to OutputGuardrail.validate(OutputGuardrailRequest).
  • Method Details

    • responseFromLLM

      public ChatResponse responseFromLLM()
      Returns the response from the LLM.
      Returns:
      the response from the LLM
    • chatRequest

      @Experimental public ChatRequest chatRequest()
      Returns the request that was sent to the model to produce responseFromLLM(), if known: when the response is the result of a tool-calling loop, the last request of the loop, whose messages include the tool calls and tool results of all rounds; when the model was asked again after a guardrail failure (reprompt), the request of that call, whose messages include the reprompt. The request is not known, for example, when that call was made by a ChatExecutor that does not override ChatExecutor.exchange(List).
      Returns:
      the request, or null if it is not known
      Since:
      1.23.0
    • chatExecutor

      public ChatExecutor chatExecutor()
      Returns the chat executor.
      Returns:
      the chat executor
    • requestParams

      public GuardrailRequestParams requestParams()
      Returns the common parameters that are shared across guardrail checks.
      Specified by:
      requestParams in interface GuardrailRequest<OutputGuardrailRequest>
      Returns:
      an instance of GuardrailRequestParams containing shared parameters
    • withText

      public OutputGuardrailRequest withText(String text)
      Description copied from interface: GuardrailRequest
      Recreate this guardrail param with the given input or output text.
      Specified by:
      withText in interface GuardrailRequest<OutputGuardrailRequest>
      Parameters:
      text - The text of the rewritten param.
      Returns:
      A clone of this guardrail params with the given input or output text.
    • builder

      public static OutputGuardrailRequest.Builder builder()
      Creates a new builder for OutputGuardrailRequest.
      Returns:
      a new builder