Interface GuardrailService.Builder

Enclosing interface:
GuardrailService

public static interface GuardrailService.Builder
Builder class for building GuardrailService instances
  • Method Details

    • inputGuardrailsConfig

      GuardrailService.Builder inputGuardrailsConfig(InputGuardrailsConfig config)
      Configures the input guardrails for the builder.
      Parameters:
      config - The configuration for input guardrails. Must not be null.
      Returns:
      The current instance of GuardrailService.Builder for method chaining.
      Throws:
      IllegalArgumentException - if config is null.
    • outputGuardrailsConfig

      GuardrailService.Builder outputGuardrailsConfig(OutputGuardrailsConfig config)
      Configures the output guardrails for the Builder.
      Parameters:
      config - The configuration for output guardrails. Must not be null.
      Returns:
      The current instance of GuardrailService.Builder for method chaining.
      Throws:
      IllegalArgumentException - if config is null.
    • inputGuardrailClasses

      <I extends InputGuardrail> GuardrailService.Builder inputGuardrailClasses(List<Class<? extends I>> guardrailClasses)
      Configures the classes of input guardrails for the Builder. Existing input guardrail classes will be cleared.
      Type Parameters:
      I - The type of InputGuardrail
      Parameters:
      guardrailClasses - A list of classes implementing the InputGuardrail interface to be used as input guardrails. May be null.
      Returns:
      The current instance of GuardrailService.Builder for method chaining.
    • inputGuardrailClasses

      default <I extends InputGuardrail> GuardrailService.Builder inputGuardrailClasses(Class<? extends I>... guardrailClasses)
      Configures the classes of input guardrails for the Builder. Existing input guardrail classes will be cleared.
      Type Parameters:
      I - The type of InputGuardrail
      Parameters:
      guardrailClasses - An array of classes implementing the InputGuardrail interface to be used as input guardrails. May be null.
      Returns:
      The current instance of GuardrailService.Builder for method chaining.
    • outputGuardrailClasses

      <O extends OutputGuardrail> GuardrailService.Builder outputGuardrailClasses(List<Class<? extends O>> guardrailClasses)
      Configures the classes of output guardrails for the Builder. Existing output guardrail classes will be cleared.
      Type Parameters:
      O - The type of OutputGuardrail
      Parameters:
      guardrailClasses - A list of classes implementing the OutputGuardrail interface to be used as output guardrails. May be null.
      Returns:
      The current instance of GuardrailService.Builder for method chaining.
    • outputGuardrailClasses

      default <O extends OutputGuardrail> GuardrailService.Builder outputGuardrailClasses(Class<? extends O>... guardrailClasses)
      Configures the classes of output guardrails for the Builder. Existing output guardrail classes will be cleared.
      Type Parameters:
      O - The type of OutputGuardrail
      Parameters:
      guardrailClasses - An array of classes implementing the OutputGuardrail interface to be used as output guardrails. May be null.
      Returns:
      The current instance of GuardrailService.Builder for method chaining.
    • inputGuardrails

      <I extends InputGuardrail> GuardrailService.Builder inputGuardrails(List<I> guardrails)
      Sets the input guardrails for the Builder. Existing input guardrails will be cleared, and the provided input guardrails will be added.
      Parameters:
      guardrails - A list of input guardrails implementing the InputGuardrail interface. Can be null, in which case no guardrails will be added.
      Returns:
      The current instance of GuardrailService.Builder for method chaining.
    • inputGuardrails

      default <I extends InputGuardrail> GuardrailService.Builder inputGuardrails(I... guardrails)
      Configures the input guardrails for the Builder.
      Parameters:
      guardrails - An array of input guardrails implementing the InputGuardrail interface. May be null, in which case no guardrails will be added.
      Returns:
      The current instance of GuardrailService.Builder for method chaining.
    • outputGuardrails

      <O extends OutputGuardrail> GuardrailService.Builder outputGuardrails(List<O> guardrails)
      Sets the output guardrails for the Builder. Existing output guardrails will be cleared, and the provided output guardrails will be added.
      Parameters:
      guardrails - A list of output guardrails implementing the OutputGuardrail interface. Can be null, in which case no guardrails will be added.
      Returns:
      The current instance of GuardrailService.Builder for method chaining.
    • outputGuardrails

      default <O extends OutputGuardrail> GuardrailService.Builder outputGuardrails(O... guardrails)
      Configures the output guardrails for the Builder.
      Parameters:
      guardrails - An array of output guardrails implementing the OutputGuardrail interface. May be null, in which case no guardrails will be added.
      Returns:
      The current instance of GuardrailService.Builder for method chaining.
    • build

      Builds and returns an instance of GuardrailService. This method configures input and output guardrails for each method of the service. Guardrails set in the builder take precedence. If none are set, it uses the method-level annotations, and if those are absent, the class-level annotations.

      The guardrails and their configuration are resolved independently of each other, and separately for input and output guardrails. Only the first source found is used: guardrails set in the builder, on the method and on the class are not combined. Guardrails set in the builder count only when there is at least one: null or an empty list does not disable the guardrails declared in annotations. Guardrail instances and guardrail classes set in the builder are both used: the instances first, then the classes.

      Returns:
      an instance of GuardrailService configured with appropriate input and output guardrails.