PromptingIntermediateClaude API
If validation fails, retry with the specific error
Give Claude back the document, its previous extraction and the exact error: it fixes format and arithmetic mistakes, but it does not invent what is missing.
Validate the output (Pydantic, JSON Schema or business rules) and, if it fails, repeat the call with three things: the original, what was extracted and the specific error. It works for format, structure and arithmetic errors. It does not help if the data is not in the source or is in another document you did not pass: there, retrying only burns tokens.
Example
"Original document: <text> Previous extraction: <JSON> Error: field 'total' = 150 but the sum of line_items = 145. Check the values and return the corrected JSON."