Skip to content

Verification Loops

Trust but verify. Then fix what fails.

After generating output, run verification checks. If checks fail, feed failures back and regenerate. Repeat until verification passes or max iterations reached.

  • Output has checkable correctness criteria
  • First-attempt accuracy isn’t reliable enough
  • The cost of verification is lower than the cost of errors
  • Automated checks exist (tests, linters, validators)
loop:
output = generate(prompt)
errors = verify(output)
if no errors: return output
if max_iterations: return failure
prompt = prompt + "Fix these errors: " + errors
  • Syntax: Does it parse? Does it compile?
  • Tests: Do provided tests pass?
  • Schema: Does it match the expected structure?
  • Constraints: Does it satisfy stated requirements?
  • Self-check: Does the model agree it’s correct?
  • Set max iterations to avoid infinite loops
  • Make error messages actionable (not just “failed”)
  • Log iterations for debugging
  • Consider whether iteration cost exceeds value
  • No iteration limit (runaway costs)
  • Vague error messages (model can’t fix what it doesn’t understand)
  • Verifying things that don’t matter
  • Not tracking iteration count (hidden cost)