Code checks the model's maths
Two scripted replies from a model. Code computes the real total and catches the wrong one.
Use plain code for anything exact (sums, dates, lookups, rules) and an LLM for fuzzy language work. The strongest designs combine both: code handles what it can, the model handles the rest, and code checks the model.
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 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write is_valid_iso_date(text) that returns True only for YYYY-MM-DD with a month 1–12 and a day that exists in that month (ignore leap years: February has 28 days).
Write route(text) that returns "code" if the text is a plain number like 42 or 3.5, and "model" otherwise.
Explain it without notes
Give two jobs you would never give an LLM and two you would, and explain the difference.
Why is "code first, model as fallback, code checks the model" a good default pipeline?
Why might a model return a date for an impossible input like 2026-13-40?
Expected output
Total computed by code: 1159.00
Model says 1159.00 -> OK
Model says 1169.00 -> MISMATCH, do not send