Learn · Prompt engineering & structured output · CCAR-F task 4.4
Validation, retry and feedback loops
Extract, validate in code, send back the specific errors, retry a bounded number of times, then route to a human.
Key ideas
- The robust pipeline: extract, validate in code, send specific errors back, retry up to N times, then route to a human.
- Validation checks business rules in code: sums, real dates, IDs that exist.
- Feedback must be specific (which field, what was expected), not "try again".
- On retry, include the original document, the failed extraction and the errors.
- Retry is futile when the information is not in the source; set null and escalate.
- Self-checking fields (stated_total, calculated_total, conflict_detected) let code catch disagreement.
Worked example: A useful feedback message
"Your previous output had these problems: line 3 qty x unit_price = 120 but total = 210; invoice_date 2026-02-30 is not a real date. Fix only these." Each error names the field, the expected value and the actual value.
Exam traps
- Unbounded retry loops with no route to a human.
- Retrying with a generic "please try again" and no specific errors.
- Retrying when the value isn't in the document at all.
- Assuming schema validation alone catches wrong values.
Official docs
Practise CCAR-F questions · Next lesson: Batch processing, and when not to