Command Palette

Search for a command to run...

Hectal
Back to the lesson: Topic 0.3 — When to Use an LLM (and When Not To)
LLM Engineering · Example 1 of 2

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.

01

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).

02

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

01

Give two jobs you would never give an LLM and two you would, and explain the difference.

02

Why is "code first, model as fallback, code checks the model" a good default pipeline?

03

Why might a model return a date for an impossible input like 2026-13-40?

Code checks the model's maths
Sign in to run this example in your browser.

Expected output

Total computed by code: 1159.00
Model says 1159.00 -> OK
Model says 1169.00 -> MISMATCH, do not send