Interface GuardrailService

All Known Implementing Classes:
AbstractGuardrailService

public interface GuardrailService
Defines a service for executing guardrails associated with methods in an AI service. Guardrails are constraints or validations applied either to input or output of a method.
  • Method Details

    • aiServiceClass

      Class<?> aiServiceClass()
      Retrieves the class representing the AI service to which the guardrails apply.
      Returns:
      The Class object representing the AI service.
    • executeInputGuardrails

      <MethodKey> InputGuardrailResult executeInputGuardrails(MethodKey method, InputGuardrailRequest params)
      Executes the input guardrails associated with a given Method
      Type Parameters:
      MethodKey - > The type of the method key, representing a unique identifier for methods.
      Parameters:
      method - The method whose input guardrails are to be executed.
      params - The parameters to validate against the input guardrails. Must not be null.
      Returns:
      The result of executing the input guardrails, encapsulated in an InputGuardrailResult. If no guardrails are associated with the method, a successful result is returned by default.
    • executeGuardrails

      default <MethodKey> UserMessage executeGuardrails(MethodKey method, InputGuardrailRequest params)
      Executes the input guardrails associated with the given method and parameters, and retrieves a modified or validated UserMessage based on the result.
      Type Parameters:
      MethodKey - The type of the method key, representing a unique identifier for methods.
      Parameters:
      method - The method whose input guardrails are to be executed. Nullable.
      params - The parameters to validate against the input guardrails. Must not be null.
      Returns:
      A UserMessage derived from the provided parameters and the result of the input guardrails execution. If guardrails are applied successfully, a potentially rewritten user message is returned. If no guardrails are associated with the method, the original user message is returned.
    • executeOutputGuardrails

      <MethodKey> OutputGuardrailResult executeOutputGuardrails(MethodKey method, OutputGuardrailRequest params)
      Executes the output guardrails associated with a given Method.
      Type Parameters:
      MethodKey - > The type of the method key, representing a unique identifier for methods.
      Parameters:
      method - The method whose output guardrails are to be executed.
      params - The parameters to validate against the output guardrails. Must not be null.
      Returns:
      The result of executing the output guardrails, encapsulated in an OutputGuardrailResult. If no guardrails are associated with the method, a successful result is returned by default.
    • hasInputGuardrails

      <MethodKey> boolean hasInputGuardrails(MethodKey method)
      Whether or not a method has any input guardrails associated with it
      Type Parameters:
      MethodKey - > The type of the method key, representing a unique identifier for methods.
      Parameters:
      method - The method
      Returns:
      true If method has input guardrails. false otherwise
    • hasOutputGuardrails

      <MethodKey> boolean hasOutputGuardrails(MethodKey method)
      Whether or not a method has any output guardrails associated with it
      Type Parameters:
      MethodKey - > The type of the method key, representing a unique identifier for methods.
      Parameters:
      method - The method
      Returns:
      true If method has output guardrails. false otherwise
    • executeGuardrails

      default <MethodKey, T> T executeGuardrails(MethodKey method, OutputGuardrailRequest params)
      Executes the guardrails associated with a given method and parameters, returning the appropriate response.
      Type Parameters:
      MethodKey - The type of the method key, representing a unique identifier for methods.
      T - The type of response to produce
      Parameters:
      method - The method whose output guardrails are to be executed. Nullable.
      params - The parameters to validate against the output guardrails. Must not be null.
      Returns:
      A ChatResponse that encapsulates the output of executing the guardrails based on the provided parameters.
    • builder

      static GuardrailService.Builder builder(Class<?> aiServiceClass)
      Creates a new instance of GuardrailService.Builder for the specified AI service class.
      Parameters:
      aiServiceClass - The Class object representing the AI service for which the builder is being created.
      Returns:
      A GuardrailService.Builder instance initialized with the specified AI service class.