Code first, the model only for what code can't parse
The fake model stands in for a real call. Notice what it says about the impossible date.
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
2026-10-10 -> 2026-10-10 (code)
10/10/2026 -> 2026-10-10 (code)
next friday -> 2026-10-16 (model, checked by code: ok)
2026-13-40 -> rejected (code: not a real date)
model calls: 1 of 4
Asked about 2026-13-40, the model says 2026-12-31: it invents a fix instead of saying no.