Retry an extraction or flag it
Sort failed extractions into those a retry with error feedback will fix and those whose information is not in the source, and add self-check fields that catch what a schema can't.
Scenario
Scenario: Structured Data Extraction. An energy-management firm extracts 9,000 utility bills a month: account number, billing period, meter readings, usage in kWh and amount due. Strict tool use is on, so every result matches the schema.
Still, 6% fail the business validator. The pipeline retries each failure three times with the same request. Some pass on the second try; most fail three times and land in a queue nobody reads. The retries cost money and fix the wrong half.
Explanation
Tool use with a strict schema, or structured outputs, guarantees the shape of the result: valid JSON, the right field types, every required field present. That removes syntax errors. It does not make the values right. What is left are semantic errors, and your own validator has to catch them:
- values that don't add up (line items vs total, previous vs current meter reading vs usage)
- a value in the wrong field (the due date in
period_end) - a format the downstream system rejects (a date written as "3rd of March")
- two parts of the document that disagree
Retry with error feedback. Re-sending the identical request mostly repeats the mistake. A useful retry is a follow-up request that holds three things: the original document, the failed extraction, and the specific validation errors ("usage_kwh is 1,240 but current minus previous reading is 1,420"). The same rule as for tool errors applies: say what went wrong, not just "invalid".
Where retry stops working. A retry helps when the answer is in the document and Claude put it in the wrong place or form: format mismatches, swapped fields, structural slips. It cannot help when the information is absent: the bill says "see attached meter schedule" and the schedule was never sent, or the field simply isn't on this document type. Then every retry either fails again or invents a value. The fix is upstream (send the missing document) or in the schema (null plus a reason), with the record routed to a person.
Self-check fields. Ask Claude to extract checks alongside the data, so your validator can tell who is wrong:
stated_totalandcalculated_total: if Claude's own sum differs from what the document says, the source may be wrong, not the extraction.conflict_detected(boolean) with a short note: the document gives two different values for the same thing.
A related field for review pipelines: detected_pattern, naming what triggered a finding, so you can count which patterns people dismiss.
Worked example
A bill fails validation: usage_kwh is 1,240, but the readings extracted are 48,310 and 49,730, a difference of 1,420.
Before: the pipeline sends the same request again. Claude reads the same table the same way.
After: a follow-up request with the document, the failed output and the error:
Below are a utility bill, your earlier extraction of it, and the errors our validator found.
Error 1: usage_kwh (1240) does not equal current_reading minus previous_reading (49730 - 48310 = 1420). Check which value the bill states as usage for this period and which meter the readings belong to.
Return a corrected extraction. If the bill itself states usage that differs from its readings, keep the stated usage and set conflict_detected to true with a one-line note.
The second run finds that the bill has two meters, and the 1,240 kWh belongs to the second one. A blind retry had no way to know which number to look at again.