Skip to content
Claude Certified Architect – Foundations (CCAR-F) Exam Prep

Lesson 22 of 30 · 6 min

x
22/30

Validation and Retry Loops

Video lesson: CCAR-F 22/30: Validation and Retry Loops

Layers of validation (design guidance, grounded in verified facts)

  1. Syntax and schema: structured outputs make valid JSON that matches the schema, so schema-violation retries are generally unnecessary (verified). Check stop_reason first: max_tokens can truncate the JSON; refusal is a 200 response that may not match.
  2. Semantic and business rules: things a schema cannot express: totals add up, dates in order, ids exist in your database, values within allowed ranges, cross-field consistency, quoted evidence actually appears in the source.
  3. Grounding: each extracted value traces to the source text (see 5.6).

Retry with feedback

When validation fails, retry with the specific failure so the model can correct it:

  • include the original input, the previous output and the exact validation error ("total is 120.00 but line items sum to 110.00");
  • ask for a corrected output only;
  • bound the retries (for example 2 to 3) and keep a record of attempts.

When a retry cannot help (design guidance)

Retrying is pointless when the information is not in the input: the model will either repeat the gap or invent a value. Recognise these cases and do not loop:

FailureRight response
Format or arithmetic slipRetry with the error
Truncated output (max_tokens)Retry with a higher limit
Required value absent from the sourceReturn null or "missing", flag for a human or ask for more input
Persistent disagreement after N triesEscalate to a human with the attempts attached
refusalRead stop_details; use the documented fallback, not blind retries

Transient vs deterministic failures

Retry transient API or tool errors (rate limit, overload, timeouts) with backoff; do not retry deterministic validation errors unchanged (2.2).

Exam traps

  • Retrying the same prompt unchanged and hoping.
  • Retry loops with no cap.
  • Retrying to fill a field the source never contained, which produces fabrication.
  • Treating a schema pass as full validation.
  • Swallowing the final failure instead of surfacing it.

References

  1. Structured outputs — checked Oct 16, 2026
  2. Handling stop reasons — checked Oct 16, 2026

Check your understanding

  • A model-extracted invoice total does not equal the sum of its line items. Action?Show answer

    Answer

    Retry with the specific discrepancy, bounded, then escalate if it persists.
  • The customer's phone number is not in the document and extraction keeps returning a fake one. Fix?Show answer

    Answer

    Allow null/missing; stop retrying; flag for review.
  • Output ended mid-JSON with stop_reason: max_tokens. Fix?Show answer

    Answer

    Increase max_tokens and retry.
Previous

Progress is saved in this browser.

Next Lesson