When It Fails, Ask Again

retry with feedback

Part of: Structured JSON Extractor

Real inputs break things. The text is empty. The model returns two fields when you needed three. A value comes back the wrong type. A production extractor recovers instead of crashing. It handles the empty case without a call, and when validation fails it asks the model again, telling it exactly what was wrong. Handle the empty case first The cheapest call is the one you don't make. Empty or whitespace-only input has nothing to extract, so short-circuit it: No tokens spent, nothing hallucinated, just a predictable all-null record. Retry with the error in the prompt When a parsed record fails validation, don't retry blindly. Tell the model what broke. Feeding the validation errors back sharpens the second attempt: Each retry appends the specific problems (missing: phone) so the model corrects that exact gap instead of guessing again. Cap the retries Retries cost money and time, and some inputs genuinely lack the data. No amount of re-asking will find a phone number that was never in the text. So cap attempts (two retries is a sane default) and, on final failure, return the best record you have with a valid: False flag. The caller decides whether to store it flagged, drop it, or send

Challenge: Retry Until Valid