Package dev.langchain4j.guardrail
Interface InputGuardrail
- All Superinterfaces:
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 Summary
Modifier and TypeMethodDescriptiondefault InputGuardrailResult
Produces a non-fatal failuredefault InputGuardrailResult
Produces a non-fatal failuredefault InputGuardrailResult
Produces a fatal failuredefault InputGuardrailResult
Produces a non-fatal failuredefault InputGuardrailResult
success()
Produces a successful result without any successful textdefault InputGuardrailResult
successWith
(String successfulText) Produces a successful result with specific success textdefault InputGuardrailResult
validate
(UserMessage userMessage) Validates theuser message
that will be sent to the LLM.default InputGuardrailResult
validate
(InputGuardrailRequest 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<InputGuardrailRequest,
InputGuardrailResult> - Parameters:
params
- the parameters, including the user message, the memory, and the augmentation result.- Returns:
- The result of the validation
-
success
Produces a successful result without any successful text- Returns:
- The result of a successful input guardrail validation.
-
successWith
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
Produces a non-fatal failure- Parameters:
message
- A message describing the failure.- Returns:
- The result of a failed input guardrail validation.
-
failure
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
Produces a fatal failure- Parameters:
message
- A message describing the failure.- Returns:
- The result of a failed input guardrail validation.
-
fatal
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.
-