diff --git a/core/runtime/src/main/java/io/quarkiverse/langchain4j/guardrails/AbstractJsonExtractorOutputGuardrail.java b/core/runtime/src/main/java/io/quarkiverse/langchain4j/guardrails/AbstractJsonExtractorOutputGuardrail.java index 488c832ca..ff25c40ab 100644 --- a/core/runtime/src/main/java/io/quarkiverse/langchain4j/guardrails/AbstractJsonExtractorOutputGuardrail.java +++ b/core/runtime/src/main/java/io/quarkiverse/langchain4j/guardrails/AbstractJsonExtractorOutputGuardrail.java @@ -40,9 +40,19 @@ public OutputGuardrailResult validate(AiMessage responseFromLLM) { } } - return reprompt("Invalid JSON", - "Make sure you return a valid JSON object following " - + "the specified format"); + return invokeInvalidJson(responseFromLLM, json); + } + + protected OutputGuardrailResult invokeInvalidJson(AiMessage aiMessage, String json) { + return reprompt(getInvalidJsonMessage(aiMessage, json), getInvalidJsonReprompt(aiMessage, json)); + } + + protected String getInvalidJsonMessage(AiMessage aiMessage, String json) { + return "Invalid JSON"; + } + + protected String getInvalidJsonReprompt(AiMessage aiMessage, String json) { + return "Make sure you return a valid JSON object following the specified format"; } protected Object deserialize(String llmResponse) {