Class JsonExtractorOutputGuardrail<T>
java.lang.Object
dev.langchain4j.guardrail.JsonExtractorOutputGuardrail<T>
- Type Parameters:
T- The type of object that the class should deserialize from JSON
- All Implemented Interfaces:
Guardrail<OutputGuardrailRequest, OutputGuardrailResult>, OutputGuardrail
@Deprecated(since="1.9.0",
forRemoval=true)
public class JsonExtractorOutputGuardrail<T>
extends Object
implements OutputGuardrail
Deprecated, for removal: This API element is subject to removal in a future version.
This class has been moved to the `langchain4j-guardrails` module and will be removed in a future release.
* Add a dependency on `dev.langchain4j:langchain4j-guardrails` and use the class from that module instead.
An
OutputGuardrail that will check whether or not a response can be successfully deserialized to an object
of type T from JSON
If deserialization fails, the LLM will be reprompted with getInvalidJsonReprompt(AiMessage, String), which
defaults to DEFAULT_REPROMPT_PROMPT.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringDeprecated, for removal: This API element is subject to removal in a future version.The default message to use when repromptingstatic final StringDeprecated, for removal: This API element is subject to removal in a future version.The default prompt to append to the LLM during a reprompt -
Constructor Summary
ConstructorsConstructorDescriptionJsonExtractorOutputGuardrail(com.fasterxml.jackson.core.type.TypeReference<T> outputType) Deprecated, for removal: This API element is subject to removal in a future version.JsonExtractorOutputGuardrail(com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.fasterxml.jackson.core.type.TypeReference<T> outputType) Deprecated, for removal: This API element is subject to removal in a future version.JsonExtractorOutputGuardrail(com.fasterxml.jackson.databind.ObjectMapper objectMapper, Class<T> outputClass) Deprecated, for removal: This API element is subject to removal in a future version.JsonExtractorOutputGuardrail(Class<T> outputClass) Deprecated, for removal: This API element is subject to removal in a future version. -
Method Summary
Modifier and TypeMethodDescriptionprotected Optional<JsonParsingUtils.ParsedJson<T>> deserialize(String llmResponse) Deprecated, for removal: This API element is subject to removal in a future version.Tries to deserialize the provided LLM response string into an object of type T using the configuredObjectMapper.protected StringgetInvalidJsonMessage(AiMessage aiMessage, String json) Deprecated, for removal: This API element is subject to removal in a future version.Generates a message indicating that the provided JSON is invalid.protected StringgetInvalidJsonReprompt(AiMessage aiMessage, String json) Deprecated, for removal: This API element is subject to removal in a future version.Generates a reprompt message indicating that the provided JSON is invalid.protected OutputGuardrailResultinvokeInvalidJson(AiMessage aiMessage, String json) Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.Validates the response from the LLM.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface OutputGuardrail
failure, failure, fatal, fatal, reprompt, reprompt, retry, retry, success, successWith, successWith, successWith, successWith, validate
-
Field Details
-
DEFAULT_REPROMPT_MESSAGE
Deprecated, for removal: This API element is subject to removal in a future version.The default message to use when reprompting- See Also:
-
DEFAULT_REPROMPT_PROMPT
Deprecated, for removal: This API element is subject to removal in a future version.The default prompt to append to the LLM during a reprompt- See Also:
-
-
Constructor Details
-
JsonExtractorOutputGuardrail
-
JsonExtractorOutputGuardrail
public JsonExtractorOutputGuardrail(com.fasterxml.jackson.databind.ObjectMapper objectMapper, com.fasterxml.jackson.core.type.TypeReference<T> outputType) Deprecated, for removal: This API element is subject to removal in a future version. -
JsonExtractorOutputGuardrail
-
JsonExtractorOutputGuardrail
Deprecated, for removal: This API element is subject to removal in a future version.
-
-
Method Details
-
validate
Deprecated, for removal: This API element is subject to removal in a future version.Description copied from interface:OutputGuardrailValidates the response from the LLM.- Specified by:
validatein interfaceOutputGuardrail- Parameters:
responseFromLLM- the response from the LLM
-
invokeInvalidJson
Deprecated, for removal: This API element is subject to removal in a future version. -
getInvalidJsonMessage
Deprecated, for removal: This API element is subject to removal in a future version.Generates a message indicating that the provided JSON is invalid.- Parameters:
aiMessage- the AI message associated with the invalid JSON. This parameter is not used.json- the JSON that failed validation. This parameter is not used.- Returns:
- a default message indicating that the JSON is invalid.
-
getInvalidJsonReprompt
Deprecated, for removal: This API element is subject to removal in a future version.Generates a reprompt message indicating that the provided JSON is invalid.This message is appended to the user message from the previous request.
- Parameters:
aiMessage- the AI message associated with the invalid JSON. This parameter is not used.json- the JSON input that failed validation. This parameter is not used.- Returns:
- a reprompt message indicating that the JSON is invalid.
-
deserialize
Deprecated, for removal: This API element is subject to removal in a future version.Tries to deserialize the provided LLM response string into an object of type T using the configuredObjectMapper. If deserialization fails, an empty Optional is returned.- Parameters:
llmResponse- the JSON-formatted response string to be deserialized- Returns:
- an Optional containing the deserialized object if successful, or an empty Optional if deserialization fails
-