fix: fallback to strict json_schema if planner response validation fails in json_mode #341
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Improved fix:
This fix improves upon the reverted PR #322 because the fix in that PR was incompatible with some LLMs. In this improved PR, the
planner
tries to generate a plan usingjson_mode
first and then using a strictjson_schema
if the first try fails.That means the code retains the existing
json_mode
when theplanner
initially tries to generate aPlan
response. Only if that initial response does not comply with the required response format and the pydantic model validation throws anOutputParserException
, then theplanner
tries to generate another plan using a strictjson_schema
to force the LLM response to strictly comply with the pydanticPlan
model. If that try also causes an exception then the user is instructed to reduce the complexity of their query.Problem:
The planner node expects an LLM response in a specific json format, but the LLM response does not always comply with that format so pydantic raises a model validation error, as reported by users in these issues:
#151
#189
#191
and possibly here:
#99
#217