AI Engineering from Scratch / Stage 2. The model in the product
Decide exactly what the model sees for one decision, and prove on 20 cases that the new context is better before you ship it.
Outcome: an A/B report
For this lesson you need: make_card from lesson 8, which checks every card value against a quote from the ticket; run_evals and the 38 cases in evals/cases.jsonl from lessons 7–8; your own cases in evals/own.jsonl, branch lesson-08; the keyless mock mode from lesson 6.
The model sees only the text your code put into the request. It knows nothing about your database, your files or the customer's ticket from yesterday.
The prompt in the narrow sense is just the last line of the request; your code puts in everything else. So this lesson is mostly about the code that builds the request.
Today the card gets a second model call: a draft reply to the customer, which an operator checks and sends. And this is where a failure shows up that you never see in a demo. The order service didn't respond, the code put an empty list into the request, and the model politely tells the customer: "We found no orders on your account." The operator is in a hurry and sends it.
What changed in the contract. The card becomes version v4:
CardResult.draft_reply: the draft reply to the customer. support/context.py: customer state update_customer_state and the chain make_card_with_reply, which also checks who owns the order. run_evals --variant A|B: context v1 (A, as before) or v2 (B). evals/cases.jsonl: five cases tagged context, from c039 to c043; their must_contain and must_not_contain check the draft text. run_evals --prompt zero|one|few|reason: how many examples go into the request (contract 1.2). --examples FILE and --reverse-examples: your own examples and reversed order. --runs N --vote: several runs and the majority answer. evals/examples.jsonl (e01–e03) and evals/examples_bias.jsonl: labeled examples and deliberately biased ones. TicketCardReasoned: a schema with a short why field that the code drops before the checks.
The lesson code is in the l09 tag. Save your work on the lesson 8 branch (git add -A, then git commit -m "кінець уроку 8") and run this in the starter folder:
If the second command prints error: pathspec ... did not match, you don't have your own cases in lesson-08 yet, and that's fine. To see what the tag added, run git diff --stat l08 l09; if you see : at the bottom, your computer hasn't frozen: that's a pager for long output, press q to exit.
Your numbers will be different. run_evals also pulls your own cases from evals/own.jsonl into the run. For you, cases = 43 + yours. Compare the differences, not the raw numbers. Runs filtered by tag (for example --tag injection) may pick up some of your cases too. (dev) in the output means the working set of cases; a separate held-out set comes in lesson 11 (still in the works).
How to run the blocks. Run the uv run ... blocks in a terminal in the starter's root folder. Run Python blocks the way you did in lesson 3: save as try_<назва>.py, run uv run python try_<назва>.py, delete the file. In the outputs, {*} means "any text can be here" and ... means "there may be more lines here".