Getting Reliable Structured Outputs from LLMs: Validation, Retries and Constrained Decoding
The fixture suite turns the sentences above into fourteen test cases, from a missing required key and a code fence around the JSON to a fabricated quote, a refusal and exhaustion with no fourth call.
We haven't written up this one. Machine Learning Mastery has the full story — the link below goes straight to it.