Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Objectives: LO-6.1, LO-6.2, LO-6.3
Prerequisites: the Module 6 reading
Time: about 2.5 hours

In this lab you choose an effort level from a table of illustrative measurements, extract a final answer from a tagged reply and reject malformed ones, and build a three-step chain. Then you compute how errors compound along the chain and what a check step catches.

No cell calls a real model. The model in Exercise L6.3 is ScriptedModel, a stand-in from promptlab that answers each request from a script, in the shape of a Messages API response, and records every request it receives. The measurements were written for this course.

Use a fresh kernel and run the cells from top to bottom. Fill each answer cell, then run its check. The checks raise errors until their exercises are complete. This notebook runs locally.

Setup

Set constraints first

Each row gives one effort level’s accuracy on labeled cases, its median latency in seconds, and its cost in relative units. The values are illustrative. Before you run the next cell, predict which row meets at least 90% accuracy and at most 2.5 seconds at the least cost.

Exercise L6.1 (LO-6.1, ★★, about 25 minutes)

Find the cheapest qualifying row. A row qualifies when its accuracy is at least min_accuracy and its seconds is at most max_seconds: both thresholds are inclusive. Among the qualifying rows, choose the lowest cost. Break cost ties by lower seconds, then by the effort name in alphabetical order. Return the effort string, or None when no level qualifies.

Exercise L6.2 (LO-6.2, ★★, about 25 minutes)

Extract a final answer. Return the text inside the reply’s one <answer> section, with its surrounding whitespace stripped. Match the tags exactly as written here, in lowercase. Use the re.DOTALL flag, which lets . match a newline too, so an answer that spans lines is found. Raise ValueError for a missing, empty, or repeated section. A second <answer> tag counts as a repeat even without its own closing tag.

Exercise L6.3 (LO-6.3, ★★, about 25 minutes)

Pass the original input forward. Call the stand-in three times. Each request has one user message, whose text begins with classify, draft, or check, followed by a newline. Include the original ticket in every step. Include the extracted label in the draft step, and the extracted reply in the check step. A response can begin with a thinking block, so read each answer from the response’s text blocks, and extract it with your extract. Return the reply when the final extracted answer is approved, and None otherwise.

Exercise L6.4 (LO-6.3, ★★, about 25 minutes)

Measure error propagation. Return a tuple (passed, missed). passed is the probability that every stage is right: the product of the conditional success rates in stage_rates. Each rate is a stage’s success rate on runs where every earlier stage was right. missed is the probability, as a share of all runs, of a failure that the check doesn’t catch. The check catches the fraction caught of the failures, and it accepts every correct result.

Summary

  • You chose an effort level by applying fixed thresholds first and a written rule second, and found that a table can leave no level that qualifies.

  • You extracted a final answer and raised an error for a missing, empty, or repeated section, so a malformed reply can’t pass for a valid one.

  • You built a chain that carries the original ticket to every step and reads answers from text blocks, and you computed how a check step changes the share of failures that get through.