Skip to content

Commit

Permalink
Merge pull request #1204 from edeandrea/enhance-json-guardrail
Browse files Browse the repository at this point in the history
Allow customization of invalid json reprompt
  • Loading branch information
geoand authored Jan 9, 2025
2 parents 7cf8fd4 + b03f26d commit 7d10993
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7d10993

Please sign in to comment.