Claude Certified Architect - FoundationsCCAR-F Learning Guide
Domain 4 · Lesson 4.4 · 5 min read

Validation, Retry and Feedback Loops

Exam taskImplement validation, retry, and feedback loops for extraction quality

Validate extractions for meaning, not just shape; retry with the document, the failed output and the exact errors; know that retries cannot recover information the document does not contain; and record patterns so dismissals can be analysed.

What you need to know

Two kinds of error

Syntax / schema errorsSemantic errors
ExampleMissing bracket, wrong typeLine items do not sum to the total; vendor name in the address field
Removed byTool use with a strict schemaValidation 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) alongside stated_total, so a mismatch is flagged instead of hidden.
  • conflict_detected: true when 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:

  1. The original document.
  2. The failed extraction.
  3. The specific validation errors: "invoice_date is 'next Tuesday'; expected YYYY-MM-DD. total is '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

Question 1

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.

Question 2

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.

Question 3

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

Exercise · about 15 minCase: Bayview Payables

About 8% of Bayview's invoices have line items that do not match the total. Design the validation and retry loop.

  1. List four validation checks, at least two of them semantic.
  2. Write the retry message for one failed check.
  3. Write the stop rule: when the loop gives up, and where the document goes.
  4. Say which failures should never be retried.
Check your work
Show model answer

1. Checks

  • calculated_total equals stated_total within 0.01 (semantic).
  • due_date is on or after invoice_date (semantic).
  • vendor_name does not look like an address, for example no postcode pattern (semantic).
  • currency is 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.

Sources

Go hands-on optional, needs a Claude API key

Runnable notebooks from Anthropic's Claude Cookbook that build the patterns in this lesson.