instructor-ai / instructor-js

structured extraction for llms
https://js.useinstructor.com
MIT License
526 stars 57 forks source link

Retries on invalid JSON response #174

Closed simoncollins closed 4 months ago

simoncollins commented 4 months ago

Having a lot of fun playing with Instructor!

One question: It appears the code currently only retries completions on Zod validation errors, not on JSON parse errors. I'm not seeing any schema validation issues with llama3 but I am seeing infrequent JSON issues such as incorrect quoting that resolve on retry.

Would it make sense to include JSON parsing as an additional error type that is part of the retry mechanism and fed back into the model to resolve?