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 Summary
Modifier and TypeMethodDescriptiondefault InputGuardrailResult
default InputGuardrailResult
default InputGuardrailResult
default InputGuardrailResult
default InputGuardrailResult
success()
default InputGuardrailResult
successWith
(String successfulText) default InputGuardrailResult
validate
(dev.langchain4j.data.message.UserMessage userMessage) Validates theuser message
that will be sent to the LLM.default InputGuardrailResult
validate
(InputGuardrailParams params) Validates the input that will be sent to the LLM.
-
Method Details
-
validate
Validates theuser message
that will be sent to the LLM.- Parameters:
userMessage
- the response from the LLM
-
validate
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 interfaceGuardrail<InputGuardrailParams,
InputGuardrailResult> - Parameters:
params
- the parameters, including the user message, the memory (maybe null), and the augmentation result (maybe null). Cannot benull
- Returns:
- The result of this validation.
-
success
- Returns:
- The result of a successful input guardrail validation.
-
successWith
- Parameters:
successfulText
- The text of the successful result.- Returns:
- The result of a successful input guardrail validation with a specific text.
-
failure
- Parameters:
message
- A message describing the failure.- Returns:
- The result of a failed input guardrail validation.
-
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
- 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
- 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.
-