What you need to know
Two kinds of error
| Syntax / schema errors | Semantic errors | |
|---|---|---|
| Example | Missing bracket, wrong type | Line items do not sum to the total; vendor name in the address field |
| Removed by | Tool use with a strict schema | Validation code that checks meaning |
Design for self-checking
Ask the model to extract values that make errors visible:
calculated_total(the sum of line items) alongsidestated_total, so a mismatch is flagged instead of hidden.conflict_detected: truewhen the document contradicts itself, such as two different totals.
Validation code then compares fields and decides whether to accept, retry or route to a person.
Retry with error feedback
A blind retry ("try again") often repeats the same mistake. An effective retry sends:
- The original document.
- The failed extraction.
- The specific validation errors: "
invoice_dateis 'next Tuesday'; expected YYYY-MM-DD.totalis 'approximately $500'; expected a number."
for attempt in range(2):
data = extract(document, feedback)
errors = validate(data) # semantic and format checks
if not errors:
break
feedback = {"previous": data, "errors": errors}
Know when retries cannot help
Retries fix format mismatches and structural mistakes. They cannot produce information the document does not contain. If the purchase order number appears only in a separate document that was not provided, three more retries will either fail or invent one. Detect this case and route it elsewhere: return null, request the other document, or send it to review.
Feedback loops on findings
For review and detection systems, add a detected_pattern field to each finding (for example empty-catch-block, string-built-sql). When developers dismiss findings, you can then analyse which patterns are dismissed most and fix the prompt for those, instead of guessing.
In the exam
Scenario 6 again, plus some Scenario 5. Look for a retry design (what goes into the follow-up), a missing value that retries cannot fix, arithmetic or field-placement errors in valid JSON, and a team that cannot tell why findings are dismissed.
Check your understanding
An extraction fails validation: the date reads "next Tuesday" and the amount "approximately $500". What should the retry include?
Show answer
Answer: D. Specific errors with the original document and the failed attempt give the model what it needs to correct the fields.
A required purchase order number exists only in a separate document that was never provided. What should happen?
Show answer
Answer: B. Retries cannot recover information that is not in the source. Further attempts either fail or fabricate.
Developers dismiss many findings, and nobody knows which kinds. What should you add to each finding?
Show answer
Answer: A. Recording the pattern behind each finding lets you group dismissals and fix the prompt for the patterns that generate noise.
Apply it: Bayview's validation loop
About 8% of Bayview's invoices have line items that do not match the total. Design the validation and retry loop.
- List four validation checks, at least two of them semantic.
- Write the retry message for one failed check.
- Write the stop rule: when the loop gives up, and where the document goes.
- Say which failures should never be retried.
Show model answer
1. Checks
calculated_totalequalsstated_totalwithin 0.01 (semantic).due_dateis on or afterinvoice_date(semantic).vendor_namedoes not look like an address, for example no postcode pattern (semantic).currencyis a valid ISO code (format).
2. Retry message. "Here is the invoice, your previous extraction and one error: the line items sum to 1,184.00 but stated_total is 1,284.00. Re-read the line items and the total. If the document itself is inconsistent, set conflict_detected to true and keep both values."
3. Stop rule. At most two retries. If errors remain, or conflict_detected is true, send the document to human review with the errors attached.
4. Never retry. Missing values that are not in the document (tax ID, purchase order number held elsewhere): return null and, where the client needs the value, flag the document for follow-up.