Validation, retry, and feedback loops
What this covers
- Retry with the specific validation error rather than a bare retry
- Recognize when retrying cannot possibly help
- Design extractions that surface their own inconsistencies
- Calculate exact relationships such as a line-item sum in application code
- Return a
conflict_detectedflag instead of resolving a source contradiction - Add a
detected_patternfield so dismissed findings become an analyzable pattern
instrument plate / 4.4
Validate, correct, and stop
Inspect three possible outputs. The validator accepts a valid result or returns specific feedback for a limited retry.
case reading / no severity
Rejected: severity is required.
Return the exact violation, then retry within an explicit limit.
Read the complete diagram as text
- State categorical quality criteria and a machine-checkable output contract.
- Generate a candidate, then validate it outside the model.
- Accept a valid result without another pass.
- For a rejected result, return the exact violation and retry within a fixed limit.
- Escalate or report failure when no retries remain. Never loop indefinitely.
Key terms
- Retry
- Trying a failed operation again under defined limits.
- Semantic validation
- Checking whether data makes sense, not only whether it has the right format.
- Structured output
- Model output constrained to a defined format that software can read reliably.
Retry with the error, not just again
A bare retry re-runs the same request and usually reproduces the same failure.
Retry with error feedback sends the follow-up carrying three things: the original document, the failed extraction, and the specific validation errors. That gives the model something concrete to correct rather than another attempt at the same guess.
Know when retrying is pointless
Retry only when another attempt has information that can help correct the failure.
- Retry helps with format mismatches and structural output errors. The information was there and came out wrong.
- Retry cannot help when the information is simply absent from the source — it lives in an external document that was never provided. No number of attempts conjures it.
Retrying an absent-information failure burns cost and latency to arrive at the same answer. The correct response is to change the input or accept a null.
Read a receipt four more times and it still won't show the warranty number the store printed on a different slip. A retry works the same way: it can fix a misreading, and it cannot add a line that was never there.
Validation means semantics
Tool use already removed syntax errors. What remains is meaning:
- line items that do not sum to the stated total
- values in the wrong field
- internally inconsistent source data
Report the conflict at the level of the field. Failing the whole extraction routes the invoice to manual entry and discards the line items, totals, and identifiers that came out correctly, which is most of the record. One contested date doesn't make the rest unusable.
Design the extraction to expose these. Extract the source's stated_total and each line item, then calculate the line-item sum deterministically in application code before writing anything downstream. Add a conflict_detected field for contradictions that require interpretation. The model should preserve source claims; code should perform exact arithmetic and compare them.
Do not push this check into the schema. Some documents genuinely contain a stated total that differs from the line-item sum. Requiring equality can push the model to change one number just to satisfy the schema, hiding the discrepancy that a person needs to review.
The record your code writes downstream. None of these field names come from the API — they are a shape you choose:
{
"stated_total": 1284.50,
"line_items": [{ "amount": 900.00 }, { "amount": 380.50 }],
"calculated_total": 1280.50,
"conflict_detected": true
}stated_total records the value printed on the document. Your code computes calculated_total from the line items. Storing both values exposes the four-dollar difference for a person to review.
Feedback loops for false positives
Add a detected_pattern field recording which construct triggered a finding. When developers dismiss findings, that field turns a pile of individual dismissals into an analyzable pattern — and a pattern is something you can fix in the prompt.
retry with feedbacksemantic validationdetected_pattern
Field note — common misconceptions
- MythThat a failed extraction is worth retrying as-is
- ActuallyRetry with error feedback carries the document, the failed output, and the specific errors.
- MythThat retries can recover information the document never contained
- ActuallyWhen information is absent from the source, change the input or accept a null instead.
- MythThat validation means checking the schema
- ActuallyCalculate the line-item sum in code and add
conflict_detectedfor source contradictions.
Guided review
Review this lesson as a study deck
Review the lesson's main ideas in five guided slides, then test yourself with three flashcards.
Open Task 4.4 study deckCross-domain reasoning
Connect this idea
Reliability connects the whole workflow
A reliable workflow must know when to stop, enforce required steps, return useful errors, validate results, and keep failures visible across agent handoffs.
Structured data still needs checks and sources
A schema controls format, validation checks meaning, batch IDs keep requests and results matched, and provenance records the evidence behind each result.
Applied practice
Practice this lesson in a lab
Use a related lab to create a decision, implementation or diagram, evidence record, and review.
- Lab 7 · CI review with a strict output contract
Make a review job distinguish a clean diff from malformed output, execution failure, and invalid evidence.
- Lab 8 · Structured extraction and batch evaluation
Compare extraction strategies against labeled synthetic data without hiding critical-field failures.