Class AbstractGuardrailExecutor.GuardrailExecutorBuilder<C extends GuardrailsConfig,R extends GuardrailResult<R>,P extends GuardrailRequest<P>,G extends Guardrail<P,R>,B extends AbstractGuardrailExecutor.GuardrailExecutorBuilder<C,R,P,G,B>>

java.lang.Object
dev.langchain4j.guardrail.AbstractGuardrailExecutor.GuardrailExecutorBuilder<C,R,P,G,B>
Type Parameters:
C - The type of GuardrailsConfig to use for configuration
R - The type of GuardrailResult to return
P - The type of GuardrailRequest to validate
G - The type of Guardrails being executed This class is sealed to restrict subclassing to only specific permitted classes, such as InputGuardrailExecutor.InputGuardrailExecutorBuilder and OutputGuardrailExecutor.OutputGuardrailExecutorBuilder. It provides methods to configure and manage the guardrails and their associated configurations, eventually culminating in the construction of a specific GuardrailExecutor.
Direct Known Subclasses:
InputGuardrailExecutor.InputGuardrailExecutorBuilder, OutputGuardrailExecutor.OutputGuardrailExecutorBuilder
Enclosing class:
AbstractGuardrailExecutor<C extends GuardrailsConfig,P extends GuardrailRequest<P>,R extends GuardrailResult<R>,G extends Guardrail<P,R>,F extends GuardrailResult.Failure>

public abstract static sealed class AbstractGuardrailExecutor.GuardrailExecutorBuilder<C extends GuardrailsConfig,R extends GuardrailResult<R>,P extends GuardrailRequest<P>,G extends Guardrail<P,R>,B extends AbstractGuardrailExecutor.GuardrailExecutorBuilder<C,R,P,G,B>> extends Object permits InputGuardrailExecutor.InputGuardrailExecutorBuilder, OutputGuardrailExecutor.OutputGuardrailExecutorBuilder
A generic abstract builder class for creating instances of GuardrailExecutor.
  • Constructor Details

    • GuardrailExecutorBuilder

      protected GuardrailExecutorBuilder(C defaultConfig)
  • Method Details

    • build

      public abstract GuardrailExecutor<C,P,R,G> build()
      Constructs and returns an instance of GuardrailExecutor. This method finalizes the building process, using the configuration and guardrails provided, to create a fully-formed GuardrailExecutor instance. The returned instance enables execution of guardrails on given parameters.
      Returns:
      A fully initialized instance of GuardrailExecutor, ready to validate interactions based on the configured guardrails and parameters.
    • config

      protected C config()
      Retrieves the current configuration instance used by this builder.
      Returns:
      The configuration set in the builder.
    • guardrails

      protected List<G> guardrails()
      Retrieves the list of guardrails configured in the builder. Guardrails are validation rules applied to interactions with the model, ensuring that inputs or outputs meet required conditions for safety and correctness.
      Returns:
      A list containing the configured guardrails.
    • config

      public B config(C config)
      Sets the configuration for the guardrail executor builder.
      Parameters:
      config - The configuration instance to be set, which implements GuardrailsConfig. This can be null if no specific configuration is required.
      Returns:
      The updated instance of the builder, allowing for method chaining.
    • guardrails

      public B guardrails(List<G> guardrails)
      Updates the list of guardrails for the builder. The provided guardrails will replace the current list of guardrails in the builder. If the provided list is null, all existing guardrails will be cleared.
      Parameters:
      guardrails - A list of guardrails to be set for the builder. It can be null, in which case the current list of guardrails will be cleared.
      Returns:
      The updated instance of the builder, allowing for method chaining.
    • guardrails

      public B guardrails(G... guardrails)
      Updates the builder with the specified guardrails. This method accepts a variadic array of guardrails, which will be used to replace the current set of guardrails in the builder. If the input is null, the existing guardrails will remain unchanged.
      Parameters:
      guardrails - An optional array of guardrails to be set for the builder. Null values are accepted and will not clear existing guardrails.
      Returns:
      The updated instance of the builder, allowing for method chaining.