Interface InputGuardrail

All Superinterfaces:
Guardrail<InputGuardrailParams,InputGuardrailResult>

@Experimental("This feature is experimental and the API is subject to change") public interface InputGuardrail extends Guardrail<InputGuardrailParams,InputGuardrailResult>
An input guardrail is a rule that is applied to the input of the model to ensure that the input (the user message) is safe and meets the expectations of the model.

Implementation should be exposed as a CDI bean, and the class name configured in InputGuardrails.value() annotation.

  • Method Details

    • validate

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

      Parameters:
      userMessage - the response from the LLM
    • validate

      default InputGuardrailResult validate(InputGuardrailParams 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<InputGuardrailParams,InputGuardrailResult>
      Parameters:
      params - the parameters, including the user message, the memory (maybe null), and the augmentation result (maybe null). Cannot be null
      Returns:
      The result of this validation.
    • success

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

      default InputGuardrailResult successWith(String successfulText)
      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)
      Parameters:
      message - A message describing the failure.
      Returns:
      The result of a failed input guardrail validation.
    • failure

      default InputGuardrailResult failure(String message, Throwable cause)
      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)
      Parameters:
      message - A message describing the failure.
      Returns:
      The result of a fatally failed input guardrail validation, blocking the evaluation of any other subsequent validation.
    • fatal

      default InputGuardrailResult fatal(String message, Throwable cause)
      Parameters:
      message - A message describing the failure.
      cause - The exception that caused this failure.
      Returns:
      The result of a fatally failed input guardrail validation, blocking the evaluation of any other subsequent validation.