Interface InputGuardrail

All Superinterfaces:
Guardrail<InputGuardrailRequest,InputGuardrailResult>

public interface InputGuardrail extends Guardrail<InputGuardrailRequest,InputGuardrailResult>
An input guardrail is a rule that is applied to the input of the model to ensure that the input (i.e. the user message and parameters) is safe and meets the expectations of the model.

Input guardrails are either successful or failed. A successful guardrail means that the input is valid and can be sent to the model. A failed guardrail means that the input is invalid and cannot be sent to the model.

A failed guardrail will stop further processing of any other input guardrails.

  • Method Details

    • validate

      default InputGuardrailResult validate(UserMessage userMessage)
      Validates the user message that will be sent to the LLM.

      Parameters:
      userMessage - the response from the LLM
    • validate

      default InputGuardrailResult validate(InputGuardrailRequest params)
      Validates the input that will be sent to the LLM.

      Unlike validate(UserMessage), this method allows to access the memory and the augmentation result (in the case of a RAG).

      Implementation must not attempt to write to the memory or the augmentation result.

      Specified by:
      validate in interface Guardrail<InputGuardrailRequest,InputGuardrailResult>
      Parameters:
      params - the parameters, including the user message, the memory, and the augmentation result.
      Returns:
      The result of the validation
    • success

      default InputGuardrailResult success()
      Produces a successful result without any successful text
      Returns:
      The result of a successful input guardrail validation.
    • successWith

      default InputGuardrailResult successWith(String successfulText)
      Produces a successful result with specific success text
      Parameters:
      successfulText - The text of the successful result.
      Returns:
      The result of a successful input guardrail validation with a specific text.
    • failure

      default InputGuardrailResult failure(String message)
      Produces a non-fatal failure
      Parameters:
      message - A message describing the failure.
      Returns:
      The result of a failed input guardrail validation.
    • failure

      default InputGuardrailResult failure(String message, Throwable cause)
      Produces a non-fatal failure
      Parameters:
      message - A message describing the failure.
      cause - The exception that caused this failure.
      Returns:
      The result of a failed input guardrail validation.
    • fatal

      default InputGuardrailResult fatal(String message)
      Produces a fatal failure
      Parameters:
      message - A message describing the failure.
      Returns:
      The result of a failed input guardrail validation.
    • fatal

      default InputGuardrailResult fatal(String message, Throwable cause)
      Produces a non-fatal failure
      Parameters:
      message - A message describing the failure.
      cause - The exception that caused this failure.
      Returns:
      The result of a failed input guardrail validation.