Interface InputGuardrail
@Experimental("This feature is experimental and the API is subject to change")
public interface InputGuardrail
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.
Implementation should throw a InputGuardrail.ValidationException
when the validation fails.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final record
Represents the parameter passed tovalidate(InputGuardrailParams)
.static class
An exception thrown when the validation fails. -
Method Summary
Modifier and TypeMethodDescriptiondefault void
validate
(dev.langchain4j.data.message.UserMessage userMessage) Validates theuser message
that will be sent to the LLM.default void
Validates the input that will be sent to the LLM.
-
Method Details
-
validate
default void validate(dev.langchain4j.data.message.UserMessage userMessage) throws InputGuardrail.ValidationException Validates theuser message
that will be sent to the LLM.- Parameters:
userMessage
- the response from the LLM- Throws:
InputGuardrail.ValidationException
- the exception throws if the validation fails.
-
validate
default void validate(InputGuardrail.InputGuardrailParams params) throws InputGuardrail.ValidationException 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.
- Parameters:
params
- the parameters, including the user message, the memory (maybe null), and the augmentation result (maybe null). Cannot benull
- Throws:
InputGuardrail.ValidationException
- the exception throws if the validation fails.
-