Correction loop

A correction loop sends the model its invalid output along with the validation error message, so that it fixes it. The number of attempts is bounded to limit cost, and a final failure is handled explicitly (fallback or error) rather than ignored.

Example

for _ in range(3):
    out = ask(prompt + erreur)
    if valide(out): break

Related concepts

The whole glossary