AI Engineering from Scratch / Stage 2. The model in the product
Work through hallucinations, grounding and abstention, then check the answer format and the evidence behind every value, so an invented order number never reaches the operator.
Outcome: `make_card` + 8 edge cases
Since lesson 6, the model fills in the card. make_card trusts its answer without checking it. That opens the door to a failure with no error at all. The model returns perfect JSON with the order number DEMO-1042, which the customer never wrote: the field is there, the type is right, the schema lets it through. The operator opens someone else's order and writes to the customer about a parcel they never ordered.
So this lesson has two different checks. Shape: are the required fields there, with the right types. Content: does each value really appear in the ticket text. The provider itself checks the shape (structured output). Only your code checks the content.
For this lesson you need: the lesson-07 branch, make_card from lesson 6 that trusts the model, run_evals, and the model you picked in lesson 7. An API key is optional: you can do the whole lesson in mock. You will switch to the lesson code in the first step, once you have seen the bug on the old code.
What changed in the contract. The card becomes version v3, and the lesson code lives under the l08 tag (a tag is a label on a finished state of the code). make_card now checks every value against a quote from the ticket and writes the verdict to checks. The code computes the amount and stores it as amount_kop, a whole number of kopiykas (hundredths of a hryvnia). The new status needs_review means "the model said something without evidence, the operator decides". The full list of new names is at the bottom, in the "Reference".
How to run the Python blocks. Same as in lesson 3: save the block as try_<назва>.py in the starter's main folder, run uv run python try_<назва>.py, and delete the file. In the outputs, {*} means "any text can be here" (a time, a run number), and ... means "more lines can be here". The author checked every output in this lesson in mock mode.
Remember lesson 6. Why does call_model retry a request only once, and only on timeout or rate_limit?
This lesson: ~55 calls, ≈ $0.005 on the default model, or $0 in mock.
The lesson is planned for two evenings, 3–4 hours in total. The first evening ends after the step "Code checks the evidence": that's where you'll find how to save your work. The second starts with the step "Money: string → kopiykas".
A make_card that lets through to the operator only values backed by a quote from the ticket and marks the rest needs_review. Money in kopiykas, computed by code. A separate status for empty text, a refusal, a cut-off answer, and broken JSON. Eight of your own edge cases in evals/own.jsonl, including an injection (prompt injection: a command slipped into the ticket text) that doesn't get through. This is the "contract and validation" criterion of the final project and your second post for the gallery.