Interface OutputGuardrail
- All Superinterfaces:
Guardrail<OutputGuardrailParams,
OutputGuardrailResult>
- All Known Implementing Classes:
AbstractJsonExtractorOutputGuardrail
@Deprecated(forRemoval=true)
@Experimental("This feature is experimental and the API is subject to change")
public interface OutputGuardrail
extends Guardrail<OutputGuardrailParams,OutputGuardrailResult>
Deprecated, for removal: This API element is subject to removal in a future version.
An output guardrail is a rule that is applied to the output of the model to ensure that the output is safe and meets the
expectations.
Implementation should be exposed as a CDI bean, and the class name configured in OutputGuardrails.value()
annotation.
In the case of reprompting, the reprompt message is added to the LLM context and the request is retried.
The maximum number of retries is configurable using quarkus.langchain4j.guardrails.max-retries
, defaulting to 3.
-
Method Summary
Modifier and TypeMethodDescriptiondefault OutputGuardrailResult
Deprecated, for removal: This API element is subject to removal in a future version.default OutputGuardrailResult
Deprecated, for removal: This API element is subject to removal in a future version.default OutputGuardrailResult
Deprecated, for removal: This API element is subject to removal in a future version.default OutputGuardrailResult
Deprecated, for removal: This API element is subject to removal in a future version.default OutputGuardrailResult
Deprecated, for removal: This API element is subject to removal in a future version.default OutputGuardrailResult
Deprecated, for removal: This API element is subject to removal in a future version.default OutputGuardrailResult
Deprecated, for removal: This API element is subject to removal in a future version.default OutputGuardrailResult
Deprecated, for removal: This API element is subject to removal in a future version.default OutputGuardrailResult
success()
Deprecated, for removal: This API element is subject to removal in a future version.default OutputGuardrailResult
successWith
(String successfulText) Deprecated, for removal: This API element is subject to removal in a future version.default OutputGuardrailResult
successWith
(String successfulText, Object successfulResult) Deprecated, for removal: This API element is subject to removal in a future version.default OutputGuardrailResult
validate
(dev.langchain4j.data.message.AiMessage responseFromLLM) Deprecated, for removal: This API element is subject to removal in a future version.Validates the response from the LLM.default OutputGuardrailResult
validate
(OutputGuardrailParams params) Deprecated, for removal: This API element is subject to removal in a future version.Validates the response from the LLM.
-
Method Details
-
validate
Deprecated, for removal: This API element is subject to removal in a future version.Validates the response from the LLM.- Parameters:
responseFromLLM
- the response from the LLM
-
validate
Deprecated, for removal: This API element is subject to removal in a future version.Validates the response from the LLM.Unlike
validate(AiMessage)
, 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<OutputGuardrailParams,
OutputGuardrailResult> - Parameters:
params
- the parameters, including the response from the LLM, the memory (maybe null), and the augmentation result (maybe null). Cannot benull
- Returns:
- The result of this validation.
-
success
Deprecated, for removal: This API element is subject to removal in a future version.- Returns:
- The result of a successful output guardrail validation.
-
successWith
Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
successfulText
- The text of the successful result.- Returns:
- The result of a successful output guardrail validation with a specific text.
-
successWith
Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
successfulText
- The text of the successful result.successfulResult
- The object generated by this successful result.- Returns:
- The result of a successful output guardrail validation with a specific text.
-
failure
Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
message
- A message describing the failure.- Returns:
- The result of a failed output guardrail validation.
-
failure
Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
message
- A message describing the failure.cause
- The exception that caused this failure.- Returns:
- The result of a failed output guardrail validation.
-
fatal
Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
message
- A message describing the failure.- Returns:
- The result of a fatally failed output guardrail validation, blocking the evaluation of any other subsequent validation.
-
fatal
Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
message
- A message describing the failure.cause
- The exception that caused this failure.- Returns:
- The result of a fatally failed output guardrail validation, blocking the evaluation of any other subsequent validation.
-
retry
Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
message
- A message describing the failure.- Returns:
- The result of a fatally failed output guardrail validation, blocking the evaluation of any other subsequent validation and triggering a retry with the same user prompt.
-
retry
Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
message
- A message describing the failure.cause
- The exception that caused this failure.- Returns:
- The result of a fatally failed output guardrail validation, blocking the evaluation of any other subsequent validation and triggering a retry with the same user prompt.
-
reprompt
Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
message
- A message describing the failure.reprompt
- The new prompt to be used for the retry.- Returns:
- The result of a fatally failed output guardrail validation, blocking the evaluation of any other subsequent validation and triggering a retry with a new user prompt.
-
reprompt
Deprecated, for removal: This API element is subject to removal in a future version.- Parameters:
message
- A message describing the failure.cause
- The exception that caused this failure.reprompt
- The new prompt to be used for the retry.- Returns:
- The result of a fatally failed output guardrail validation, blocking the evaluation of any other subsequent validation and triggering a retry with a new user prompt.
-
OutputGuardrail
instead