Class DecisionModelOutputGuardrail.Builder

java.lang.Object
dev.langchain4j.guardrails.DecisionModelOutputGuardrail.Builder
Enclosing class:
DecisionModelOutputGuardrail

public static class DecisionModelOutputGuardrail.Builder extends Object
Since:
1.21.0
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • decisionModel

      public DecisionModelOutputGuardrail.Builder decisionModel(DecisionModel decisionModel)
      Sets the decision model that answers the checks. Required.
    • check

      public DecisionModelOutputGuardrail.Builder check(String name, String question)
      Adds a check. At least one check is required, and check names must be unique.
      Parameters:
      name - the name of the check, included in the failure message, for example "personalData".
      question - a yes/no question where "yes" means the response must be rejected, for example "Does the response reveal personal data?".
    • check

      public DecisionModelOutputGuardrail.Builder check(String name, String question, Double threshold)
      Adds a check with its own threshold, which overrides the threshold of the guardrail (see threshold(Double)) for this check: for example, a low threshold for a check that must rarely miss, and a high one for a check that should only reject clear cases. All checks are still answered in a single call.
      Parameters:
      name - the name of the check, see check(String, String).
      question - a yes/no question where "yes" means the response must be rejected.
      threshold - the probability of "yes", from 0 to 1, from which this check fails, or null to use the threshold of the guardrail.
    • checks

      Sets the checks, as yes/no questions keyed by check name, replacing the checks added so far. See check(String, String).
    • threshold

      public DecisionModelOutputGuardrail.Builder threshold(Double threshold)
      Sets the probability of "yes" from which a check fails, for the checks without their own threshold (see check(String, String, Double)).

      Default value is 0.5. A check fails when the probability of "yes" is greater than or equal to it. Unlike the minProbability of components that select something, reaching it rejects the response.

    • reprompt

      public DecisionModelOutputGuardrail.Builder reprompt(String reprompt)
      Sets the instruction sent to the model when a response is rejected, to ask it for a new response. Optional: by default, a rejected response fails with a fatal result.
    • build