Package dev.langchain4j.guardrail
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 ofGuardrailsConfig
to use for configurationR
- The type ofGuardrailResult
to returnP
- The type ofGuardrailRequest
to validateG
- The type ofGuardrail
s being executed This class is sealed to restrict subclassing to only specific permitted classes, such asInputGuardrailExecutor.InputGuardrailExecutorBuilder
andOutputGuardrailExecutor.OutputGuardrailExecutorBuilder
. It provides methods to configure and manage the guardrails and their associated configurations, eventually culminating in the construction of a specificGuardrailExecutor
.
- 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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract GuardrailExecutor
<C, P, R, G> build()
Constructs and returns an instance ofGuardrailExecutor
.protected C
config()
Retrieves the current configuration instance used by this builder.Sets the configuration for the guardrail executor builder.Retrieves the list of guardrails configured in the builder.guardrails
(G... guardrails) Updates the builder with the specified guardrails.guardrails
(List<G> guardrails) Updates the list of guardrails for the builder.
-
Constructor Details
-
GuardrailExecutorBuilder
-
-
Method Details
-
build
Constructs and returns an instance ofGuardrailExecutor
. This method finalizes the building process, using the configuration and guardrails provided, to create a fully-formedGuardrailExecutor
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
Retrieves the current configuration instance used by this builder.- Returns:
- The configuration set in the builder.
-
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
Sets the configuration for the guardrail executor builder.- Parameters:
config
- The configuration instance to be set, which implementsGuardrailsConfig
. This can be null if no specific configuration is required.- Returns:
- The updated instance of the builder, allowing for method chaining.
-
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
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.
-