What repairs cost, with example prices
Prices are example numbers. Read your provider's price page and keep prices in configuration.
When a reply fails validation, tell the model what was wrong and ask again, up to a fixed number of attempts, then fall back to a safe value. This fixes most failures at the cost of extra calls, so count the attempts and the money.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 6 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write retry_until_valid(model, check, max_attempts) where model() returns text and check(text) returns an error string or None. Return the first valid text, or None after max_attempts calls.
Write feedback(problems) that returns the message to send to the model: That reply was rejected: p1; p2. Reply again with only the corrected JSON.
Explain it without notes
Why does sending the validation error back to the model help?
How do you choose max_attempts?
What should a fallback look like, and why must it be flagged?
What does a repair loop cost, and how would you reduce it?
Expected output
1 attempt(s): 0.000240 dollars
2 attempt(s): 0.000545 dollars
3 attempt(s): 0.000915 dollars
1,000 requests with repairs: 0.2620 dollars
1,000 requests if all were fine: 0.2400 dollars
repairs add 9 percent