Stepping Into Production
“Can I trust what comes back, and what it does?”
Your LLM feature is live. Now someone has to answer for it. Learn to know whether it is any good, keep it running, change it safely and keep it secure.
Second edition, December 2026: paperback, 7 × 10 in, 610 pages, and a Kindle ebook. Companion code is free and open source.
A quick look at what the book covers, if you would rather watch than read.
Made with Remotion. Music generated with ElevenLabs. AI-generated content, labelled as such on YouTube.
"Your LLM feature is live. Now someone has to answer for it."
You follow one fictional company's AI support assistant through six realistic incidents. An alert routes to the wrong queue and a refund is paid twice. A "small" prompt tweak passes because the LLM judge rated it excellent. A system shows green on every dashboard while it invents a return policy. The monthly bill doubles. For each incident you build the thing that would have stopped it.
This book is for software engineers, ML engineers, SREs and tech leads who ship LLM features or AI agents and now have to keep them good, reliable, affordable and safe.
Nothing crashes. The output is simply wrong.
A clear ticket in the wrong queueIt works, too slowly to be useful.
The one kind a latency graph showsFine on average, bad for a subset, or drifting.
Fine on average, slipping day by dayIt works, and the bill doubles.
The monthly bill doublesIt does something it was tricked into.
A fake supervisor's note gets a $400 refundOne fictional company, Crateway Market, and one support assistant called Relay, run through every chapter. Every chapter starts with something that went wrong and explains it in plain English. It then works through every hard idea step by step on real values, shows the output the code really prints, with technical diagrams, and ends with one deliverable you can use on Monday.
Measure whether an LLM system is any good: evals, honest statistics, judges, agent grading, datasets and RAG.
Reliability and observability: retries, failover, traces, SLOs and error budgets, and the quiet decay you would never see.
Cost and capacity, prompts as code, evals in CI/CD, canaries, rollbacks and model upgrades.
Prompt injection, least privilege, audit trails, regulation, incident response and running the program.
Each Part answers one question and ends with a short level-up check: five yes-or-no questions about your own system.
“Can I trust what comes back, and what it does?”
“Is it any good, and can I prove it?”
“Does it stay up and stay good, and will I know when it does not?”
“Can I afford it, and can I change it safely?”
“Is it safe, and is it allowed?”
“What do we do when it breaks, and how does the team run this without heroes?”
Titles vary and are not settled. What matters is what you are accountable for, and that grows in a rough order. The book is built to climb it.
"It works." The output is checked and the tools are safe.
Part I"It is good, and I can prove it."
Part II"It stays up, stays good, stays affordable, and changes safely."
Parts III and IV"It is secure, governed and recoverable, and it runs without heroes."
Parts V and VIOpen a Part to see its chapters. The chapters, their order and their numbers are the same as in the first edition; every chapter ends with one deliverable you can take back to your own system.
What changes between “it works” and “it is in production”, the five new kinds of failure, the role ladder and the six incidents at Crateway.
A model call as a metered function, how it becomes a feature, the agent loop, and a map of twelve ways it fails.
The validation gateway, a repair loop that stops, tool contracts, and idempotency keys so a retry never pays twice.
Cases, pass criteria and graders you can trust. Build and run a 30-case eval in plain Python.
Why one run lies: pass@k, standard errors, 95% intervals, the bootstrap and paired comparison.
Judge prompts with anchored rubrics, five biases that make a judge lie politely, and validating a judge with Cohen's kappa.
Grade the outcome, not the reply: state checks, trajectories, trigger cases, simulated customers and sandboxes.
Golden sets, dataset cards, double-labeling, a contamination guard, synthetic data and the feedback flywheel.
Judge retrieval and generation separately, triage a wrong answer with two questions, and treat chunking as an experiment.
Why retries multiply, backoff with jitter, shared retry budgets, deadlines, circuit breakers and step guards.
Routers and adapters, failover that cannot flood the backup, service tiers, streams that die midway, cancellation.
Why status codes miss quiet failures: span types, a tracer in a page of Python, OpenTelemetry and handoffs.
Golden signals for an agent, SLIs and SLOs, quality SLIs from a judged sample, error budgets and burn-rate alerts.
Baselines and segment-aware bands, three kinds of drift, PSI, chi-square and KS tests, and alert routing.
Token economics, FinOps in small pieces, cascades and caching, and how to prove a saving without losing quality.
Versioned prompts, eval tiers on every pull request, and a non-inferiority gate that blocks or warns.
The release ladder, shadow testing, a self-rolling-back canary, rehearsing failure and the life of a model.
Prompt injection, excessive agency, layered guardrails, risk tiers, and safety evals that report over-refusal too.
Least privilege, audit trails, change control, a dated map of the EU AI Act, SOC 2 and NIST (not legal advice), human review.
When to declare, the containment ladder with a kill switch, compensating actions and the blameless postmortem.
A RACI sheet, on-call and runbooks, readiness reviews and game days, a maturity ladder and a rollout plan.
The second edition works through every hard idea step by step on real values, with technical diagrams and the output the code really prints. Diagrams and charts are drawn by code. Click any image to enlarge it.
A scripted stand-in for the Relay assistant means you can run every example, break it, and watch the tests catch it. Every code listing printed in the book exists in the repository, every printed output is produced by that code, and the tests run on every change. Each edition's code lives in its own directory; this edition's is second-edition/.
# timeouts, throttling and transient server trouble RETRYABLE = {408, 429, 500, 502, 503, 504, 529} def amplification(retries, layers): """Return the calls one request can cause if every layer retries.""" return (retries + 1) ** layers # ... inside call_with_retry: window = backoff_window(n, base, cap) sleep = (retry_after or 0) + rng.uniform(0, window) if sleep >= round(deadline - clock.now(), 6): # exit 5 return False, f"{status}: no time left before the deadline" if not retry_budget.allow_retry(): # exit 6 return False, f"{status}: retry budget is empty"
$ python3 -m venv .venv $ .venv/bin/pip install -r second-edition/requirements-dev.txt $ cd second-edition && ../.venv/bin/python -m pytest -q
Short Python that runs offline, with no API key and no cloud account: a scripted Relay stand-in and a fake clock.
From a metered model call and a validation gateway to a canary controller, an audit trail and a quarterly program report.
The code is consistent from chapter to chapter. Printed listings must exist in the repo, printed outputs must be real program output, and it is tested on Python 3.10 to 3.13.
Open source under the MIT License. The blank templates are in second-edition/templates/; vendor-library snippets live in clearly marked optional/ folders.
You need to have called an LLM API and be willing to read short Python. No data-science background required. Pick the path that matches your job.
Ten of the 21 chapters that give you the core: measure, validate, retry, set targets, defend, respond, own.
Everything about measuring quality, then drift, CI gates, safe releases and safety evals.
Keep it up first, then measure it, then watch it, change it and respond when it breaks.
Every deliverable in one place, with blocking groups, owners and evidence dates.
A list of the blank forms (SLO sheet, eval plan, runbook, postmortem, risk tiers, readiness checklist). The forms are files in the companion repository under second-edition/templates/.
"If something is wrong right now": find the sentence closest to what you see, then what to do first.
One row per formula you will want at the desk, each pointing to the chapter that shows the working.
The libraries, standards and services the book names, with version, date and status as of 5 October 2026.
A developer's map of EU law, SOC 2 and NIST. Dated, and not legal advice.
Plus a glossary and an index. Sources are cited in the footnotes of the chapters that use them.
It grew out of three video courses the author made on LLM evaluation, production reliability engineering and AgentOps. The author planned it, chose its running example and its incidents, and is responsible for what it says. AI tools were used in writing this book and its companion code; the author directed, edited and checked all of it.
The book checks itself instead of asking for trust. Each printed listing must exist in the companion repository, each printed output must be produced by that code, and the tests must pass on every change. Where the book states a fact about the world, it names the source and the date it was read. Mistakes may still remain; please report them on the books page.
Software engineers, ML engineers, SREs and tech leads who ship LLM features or AI agents and now have to keep them good, reliable, affordable and safe. You need a little Python and a rough idea of an LLM API call. No data-science background is needed.
The chapters, their order and their numbers are the same, and so are the story and its incidents. What changed is how each chapter teaches: every hard idea is now worked through step by step on real values, with the output the code really prints, and 35 of the book's 73 diagrams and charts are new. The companion code was made consistent from chapter to chapter and tested again, and the blank templates are now files you can copy from the repository. The second edition replaces the first.
No. All the code is short Python that runs offline, with no API key and no cloud account: every example outside the optional Tool Boxes runs against a small scripted stand-in for the Relay assistant. You replace one function with a call to your own model when you are ready.
No. Tools appear as examples in clearly dated, skippable Tool Boxes, each with the version and the date it was checked. The ideas outlast the tools, and Appendix E lists them all in one snapshot.
Yes. Chapter 0 lays out three reading paths: a fast path through ten of the 21 chapters, an evals-first path and an ops-first path. If something is wrong right now, start with Appendix C, the symptom guide.
The blank templates (SLO sheet, eval plan, runbook, postmortem, risk tiers, readiness checklist) are files in the free companion repository, under second-edition/templates/, ready to copy. Appendix B lists them, and each chapter's deliverable shows its form filled in.
Yes, and the book says so plainly. AI tools were used in writing this book and its companion code; the author directed, edited and checked all of it. The book also checks itself: each printed listing must exist in the companion repository, each printed output must be produced by that code, and the tests must pass on every change.
The second edition, December 2026: a 610-page paperback (7 × 10 inches) and a Kindle ebook, published independently and sold on Amazon. Both are on sale now.
On the author's books page, https://omkamal.github.io/books/index.html. Tools, models and regulations move quickly, which is why each one carries a version and a date.
The second edition: every hard idea worked through step by step on real values, so you know whether it is any good, keep it running, change it safely and keep it secure.
Get the paperback Get the Kindle edition