Part 11›
✎

04. Capstone 3: From Model to Product#

Level: Practitioner · Reading time: 20 min · Exercise: 40 h Prerequisites: Goals and Requirements, Planning for Mistakes, Measuring Model Quality. Read the other chapters of parts 07 and 08 as each milestone needs them.

In one sentence: After this project you have taken one feature with a classical machine-learning component, not an LLM, from a vague request to a monitored service, with a document for every decision along the way.

Why this matters#

Not every feature with a model is an LLM feature. A classifier inside an ordinary product needs the same discipline, and the discipline is easier to see there. A model predicts a label. The label drives an action. The action has a cost.

Part 07 teaches that discipline from Kästner's Machine Learning in Production, on one running example: support tickets routed to the team that can solve them. Part 08 teaches how to test it. This capstone asks you to build the whole thing once, end to end, so that the habit is yours.

The goal#

Take one feature with a classical ML component through the book's whole discipline: goals, requirements, planning for mistakes, guardrails, a pipeline, deployment and monitoring. The suggested feature is a ticket router. It reads an incoming support ticket and predicts which team should handle it: billing, technical, or another team. If you have a real feature at work, use that instead, with personal data removed.

You finish with a small service and a folder of documents that show why each design decision was made.

Deliverables#

  1. Goals and requirements. Four goal layers, one measure each, and requirements in three kinds.
  2. A baseline and a decision. The simplest rule, measured, and a written answer to "is ML worth it here?".
  3. A quality report. A confusion matrix, precision and recall per class, and a slice table.
  4. A mistake analysis. System failures, an FMEA table, a fault tree, and the design changes.
  5. A pipeline. One command runs data checks, training, the evaluation gate and the export.
  6. A deployment. The model behind an interface, with guardrails, a fallback and a model card.
  7. An operations plan. Objectives, monitors, a rehearsed rollback, a kill switch, and an incident response plan.

The feature#

Part of the feature What it does
Keyword rules Catch the obvious tickets. Anything with "invoice" goes to billing
Classifier Predicts the team for the rest, with a confidence score
Guardrail Accepts only labels from the current list
Threshold rule Below a confidence threshold, the ticket goes to the general queue
Fallback If the model is down, slow, or returns something unparseable, the general queue takes every ticket
Appeal A "wrong team?" button on every routed ticket
Telemetry Re-routes per team, fallback rate, latency

The model can be a logistic regression or a small set of decision trees on text features: for a start, a count of each word in the ticket. The point of the project is everything around it.

Milestones#

Milestone 1: goals, requirements and the decision (7 to 9 hours)#

Read When to Use ML, and When Not To, Goals and Requirements and Measuring Model Quality.

Write the goals at four layers. Organization: tickets reach the right team sooner. Product: the median time to first response falls. Users: a customer with an urgent ticket is not misrouted. Model: the share of tickets routed to the wrong team, on held-out data. Then write the requirements in three kinds. A REQ is a state you want in the world. An ASM is an assumption the software makes about the world. A SPEC is what the software must do.

Milestone 2: measure quality and find where it fails (6 to 8 hours)#

Read Slicing: Finding Where the Model Fails and Explainability, Fairness and Safety.

Milestone 3: plan for mistakes and design the system (8 to 10 hours)#

Read Planning for Mistakes, Architecture for ML Systems, Quality Attributes of ML Components and System Quality: End-to-End Tests and Guardrails.

Milestone 4: build the pipeline and deploy (8 to 10 hours)#

Read Deploying a Model, Automating the Pipeline, Data Quality, Pipeline Quality and Responsible Engineering, Versioning and Reproducibility.

Milestone 5: operate (6 to 8 hours)#

Read Planning for Operations, Testing and Experimenting in Production and Automating the Pipeline.

You are done when#

  1. The baseline number and the decision to use ML are on record, and the model beats the baseline on the test set.
  2. The quality report has the confusion matrix, the precision and recall per class, and the slice table with a decision per slice.
  3. The mistake analysis has no minimal cut set of size one without a written acceptance.
  4. The pipeline runs with one command, stops on dirty data, and refuses a model worse than the baseline.
  5. The tests with the hostile stub pass for the unknown label, the low confidence and the dead model.
  6. The rollback was rehearsed and timed, and the kill switch was tested.
  7. Every document names its date and the versions it refers to.

Effort, tools and cost#

Plan on 35 to 45 hours over three to four weeks. You need Python 3.10 or newer and a library for classical machine learning, such as scikit-learn, which Pipeline Quality names. For the data, use your own labeled tickets with personal data removed, or a public dataset whose license allows your use. Models of this kind train on a laptop at this data size. A container and a continuous integration service are optional. Hosting the service in the cloud costs money. A library call behind an interface is enough to pass the tests.

Stretch goals#

Pitfalls#

  1. Starting with the model. Fix: milestone 1, in full, before any training.
  2. An accuracy without a baseline. Fix: the keyword rules, scored first.
  3. A pipeline that fails silently. Fix: schema checks that stop the run, and retries that are counted.
  4. Two encoders. One prepares the features for training and another for prediction. Fix: one function, called by both, with a test.
  5. Set and forget. Fix: a retraining trigger, and guards for drift.
  6. A reviewer who approves all day. Fix: prompt for the few cases that matter, and measure how often reviewers disagree.
  7. A guardrail from the same model. It shares the blind spot. Fix: a plain rule, or a model trained for another task.
  8. No fallback. Fix: decide and test what happens when the model is down, slow, or returns garbage.
  9. A rollback nobody rehearsed. Fix: rehearse it and time it, before the launch.
  10. Test data in the training set. Fix: split first, and keep the test set for the final number.

What the practitioners say#

Try it#

The project is the exercise. Start with one hour:

  1. Write the four goals for a ticket queue you know.
  2. Find or label 100 tickets.
  3. Write one keyword rule and count how many of the 100 it routes correctly.

You are done with the first hour when you have one number for a rule that cost no model at all.

Key takeaways#

Self-check#

  1. Why measure the keyword baseline before training anything?
  2. What are REQ, ASM and SPEC, and which kind is "tickets arrive with a subject line"?
  3. A fault tree shows a minimal cut set with one event. What are the two ways to change that?
  4. Why must one function prepare the features for training and for prediction?
  5. What does the hostile stub model let you test that a real model cannot?
  6. Which three signals show whether the router was right in production?
Show answers 1. It is the number every model must beat, and it may be good enough. If a rule solves the problem, the cost table shows that ML would add cost without benefit. 2. A REQ is a state you want in the world. An ASM is an assumption the software makes about the world. A SPEC is what the software must do. "Tickets arrive with a subject line" is an ASM. 3. Add an independent event that must also fail, such as a second check or a person's review. Or remove the event by redesigning, so that it can no longer occur. 4. Two encoders drift apart. The model is then trained on features that differ from the ones it sees in production. That mismatch is training–serving skew. 5. The failure modes you need to survive but cannot produce on demand: an unknown label, a low confidence, a dead or slow model. 6. The re-route rate per team, the share of "wrong team?" appeals, and reopen requests. The fallback rate and the latency show only that the service runs.

Sources#

Next#

→ Capstone 4: Efficient Inference, for making a model smaller and faster without losing what it can do.