I might be reading the code wrong but it looks like it crawls the schema making a generation per primitive type. While that’s a clever way to ensure valid JSON, I don’t know if I’d go as far as to describe it as efficient.
Saying that if the model is unable to generate JSON due to its training/fine tuning, this is indeed a clever solution!
It’s clever if you’re running your own models, or only paying for tokens generated.
Since you’re generating the variable fields anyway, it will actually require fewer forward passes even if broken up in multiple prompts than if you generated the static fields as well.
Of course this doesn’t work for OpenAI apis which charge for input context on a per invocation basis.
Saying that if the model is unable to generate JSON due to its training/fine tuning, this is indeed a clever solution!