These exercises practice retrieving what the Module 6 reading explained. They aren’t graded. Work each one on paper first, then check your answer, and only then confirm it with code from Lab 6 if you like. Every measurement here is illustrative, written for the course; no model was measured. The answers are in the collapsed blocks; open one only after you have an answer of your own.
Worked example: the rule picks the level¶
A program routes tickets with Haiku 5.5. Before measuring, the team writes two thresholds: at
least 95% of labeled tickets routed correctly, and a median latency of at most 1.0 second. Its
rule picks the cheapest level that meets both. Each request has 300 input tokens, and the output
tokens include thinking. At Haiku 5.5’s $0.10 input and $0.50 output prices per million
tokens:
| Effort | Correct | Median latency | Output tokens | Cost per 1,000 requests |
|---|---|---|---|---|
low | 96% | 0.6 s | 40 | $0.05 |
medium | 98% | 0.9 s | 120 | $0.09 |
high | 98% | 1.4 s | 400 | $0.23 |
For low, one request costs (300 × 0.10 + 40 × 0.50) / 1,000,000 = 0.00005 dollars, so 1,000
cost $0.05.
Apply the thresholds first.
low(96%, 0.6 s) andmedium(98%, 0.9 s) meet both;highmisses the latency ceiling.Apply the rule to the two that pass.
lowcosts less, so the program useslow.
medium is more accurate, and it is tempting to pick it anyway. But the rule was written before
the measurements, and it says least cost. If two more points of accuracy are worth $0.04 per
1,000 tickets, the requirement should say so: raise the floor to 97%, and the same steps pick
medium.
Exercise P6.1 (LO-6.1, ★, about 10 minutes)¶
Change the lab’s median latency limit to 1.5 seconds while keeping 90% accuracy. Which effort
qualifies? The lab’s table gives low 85% at 1.2 seconds, medium 92% at 2.0 seconds, and high
94% at 3.4 seconds.
Hint
Check the thresholds before ordering by cost.
Another hint
Check low against the accuracy floor, and the other two levels against the new latency ceiling.
Answer
None. low is fast enough (1.2 seconds is at most 1.5), but its 85% misses the 90% floor. medium (2.0 seconds) and high (3.4 seconds) are accurate enough but too slow. Every level fails one threshold, so the right report is “no level qualifies.”
The common mistake is choosing low because it is the only level under the new ceiling, which quietly lowers the accuracy floor to 85%. Another is choosing medium as the nearest miss. Either way, the program would run at a level that breaks a requirement nobody agreed to change. What to do next is a decision: relax a requirement on purpose, or change the prompt or the model and measure again. Lab 6’s choose returns None for this case.
Worked example: breaking one rule at a time¶
The reading’s extractor returns the text of exactly one nonempty <answer> section. A separate
label check then accepts only repair, billing, or account, and compares the result with the
expected label. Write two replies to the billing ticket T12 that the extractor should accept but
the label check should reject, each for a different reason.
List the label check’s rules and break one at a time, keeping the reply’s shape valid:
The answer must be a queue name.
<evidence>final charge</evidence><answer>refund</answer>has one nonempty section, so the extractor returns"refund". The label check rejects it:refundisn’t a queue.The queue must match the label.
<answer>account</answer>extracts to"account", a valid queue name, and the label check rejects it because T12’s label isbilling.
Breaking one rule per reply makes each test say exactly what it checks. A reply that broke both rules at once would fail without showing which rule caught it.
Exercise P6.2 (LO-6.2, ★★, about 15 minutes)¶
Write two distinct responses that a tag extractor should reject.
Hint
List the ways a reply can fail the extractor’s one rule: exactly one nonempty section.
Another hint
Try a well-formed empty answer.
Answer
<answer> </answer> and <evidence>receipt</evidence> should both fail. The first has an answer section, but it holds only a space, which is empty after stripping. The second has no answer section at all. They fail for different reasons, which is what “distinct” asks for.
Other correct choices:
Two answer sections, such as
<answer>billing</answer><answer>repair</answer>An unclosed section,
<answer>billing, as in a reply cut off atmax_tokensAn opening tag with no closing tag of its own,
<answer><answer>billing</answer>
A common mistake is writing two replies that fail for the same reason, such as Billing. and The queue is billing., which both lack the section. Another is choosing a reply the extractor should accept, such as <answer>Billing</answer>. It has one nonempty section, so extraction returns "Billing"; whether that is a valid label is the next check’s job.
Worked example: what a check catches¶
A two-stage chain has conditional success rates 0.8 and 0.75, and a check catches 3/4 of the incorrect results while accepting every correct one. What share of all runs is correct, rejected, and accepted while incorrect?
Both stages are right on 0.8 × 0.75 = 0.60 of runs, so 1 − 0.60 = 0.40 of runs are incorrect.
The check rejects 0.40 × 3/4 = 0.30 of all runs.
The rest of the incorrect runs pass: 0.40 × 1/4 = 0.10 of all runs.
So 0.60 of runs are correct, 0.30 are rejected, and 0.10 of all runs still accept an incorrect result. The three shares add up to 1, which is a quick check on the arithmetic.
Exercise P6.3 (LO-6.3, ★★, about 15 minutes)¶
A chain returns correct answers half the time. Its check catches four in five incorrect answers and no correct ones. How often do incorrect answers get through?
Hint
The denominator is all runs.
Another hint
First find the share of all runs that are incorrect, then the share of those the check misses.
Answer
0.5 × 0.2 = 0.10 of all runs. Half of all runs are incorrect, and the check misses one in five of them. “Catches no correct ones” means it accepts every correct answer, so it adds no new failures.
The common mistake is answering 0.2, which is the share of the incorrect answers that get through, not the share of all runs. Another is answering 0.4, which is the share of all runs the check rejects.
Worked example: designing a chain¶
A one-step assistant confirms service appointments, and it often states the wrong slot length. Handbook section H02 says repairs are booked in 30-minute slots. A three-step design:
Extract the requested service and time from the customer’s message.
Draft the confirmation from the extracted details and section H02.
Review the draft against section H02 and the original message, and return
approvedorrejectedwith a reason.
Each step gets the original message, so the review can catch an extraction mistake. To compare the design with the one-step assistant, run both on the same labeled messages. Report the share of correct confirmations, the cost, and the latency for each. The chain makes three calls, so expect it to cost more and take longer; the comparison says whether the accuracy is worth it.
Exercise P6.4 (LO-6.3, ★★★, about 25 minutes)¶
A one-step assistant has weak invoices but good receipts. Design a three-step alternative and say how to compare it.
Hint
Keep the original request available for checking.
Another hint
Split the comparison by request type, so a gain on invoices can’t hide a loss on receipts.
Answer
Extract task and references, draft a response, then verify it against the original. Compare accuracy by request type, cost, and latency on the same cases.
In more detail: step 1 extracts what the customer wants (an invoice or a receipt) and the invoice reference. Section H03 of the handbook says a receipt copy needs one. Step 2 drafts the reply from the extraction and the policy. Step 3 checks the draft against the original request and the policy. Every step sees the original request, so a wrong extraction can be caught.
Run both designs on the same labeled cases, and report invoices and receipts separately. The point is to fix invoices without breaking receipts, and an overall rate could hide a receipt regression behind an invoice gain. Report the chain’s three calls’ cost and latency against the single call’s. Module 7 shows how to tell whether a difference on those cases is larger than chance.
A common mistake is a chain whose later steps see only the earlier steps’ output. Another is comparing the two designs on different cases, which mixes the difference between the designs with the difference between the case sets.