Second edition · A gentle guide to evals, observability and AgentOps

LLM Evaluation & Reliability Engineering

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.

Cover of LLM Evaluation and Reliability Engineering, second edition: a cool grey cover with a staircase of black and outlined squares, one red square, and SECOND EDITION in red.
610pages, second edition
21chapters in 6 Parts
73diagrams and charts
35of them new in this edition
6incidents, each with its fix
6appendices, glossary and index
22-second trailer

Your AI agent shipped. Is it still working?

A quick look at what the book covers, if you would rather watch than read.

  • Evals that hold up
  • Traces you can read
  • SLOs and error budgets
  • Canaries and kill switches

Made with Remotion. Music generated with ElevenLabs. AI-generated content, labelled as such on YouTube.

Why this book

Shipping was the easy part.

"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.

A map of boxes: User, Gateway, Model, Tools, Index, Telemetry, On-call, Release. Circles numbered 1 to 12 mark where each failure occurs. Dotted arrows, User to Gateway, Index to Tools and Tools to Model, carry outside text in.
Chapter 1. Twelve ways it fails: circles 1 to 12 mark where each failure sits; dotted arrows carry outside text across the trust boundary.
Silent

Nothing crashes. The output is simply wrong.

A clear ticket in the wrong queue
Slow

It works, too slowly to be useful.

The one kind a latency graph shows
Statistical

Fine on average, bad for a subset, or drifting.

Fine on average, slipping day by day
Costly

It works, and the bill doubles.

The monthly bill doubles
Unsafe

It does something it was tricked into.

A fake supervisor's note gets a $400 refund
Four skills, one story

Together they are what people call AgentOps.

One 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.

1

Evaluate

Measure whether an LLM system is any good: evals, honest statistics, judges, agent grading, datasets and RAG.

2

Keep it running

Reliability and observability: retries, failover, traces, SLOs and error budgets, and the quiet decay you would never see.

3

Change it safely

Cost and capacity, prompts as code, evals in CI/CD, canaries, rollbacks and model upgrades.

4

Secure and govern

Prompt injection, least privilege, audit trails, regulation, incident response and running the program.

The structure

Six Parts. Six questions. Four levels of responsibility.

Each Part answers one question and ends with a short level-up check: five yes-or-no questions about your own system.

Part I

Stepping Into Production

“Can I trust what comes back, and what it does?”

Level 1: BuilderChapters 0 to 2
Part II

Know If It Is Good

“Is it any good, and can I prove it?”

Level 2: Quality ownerChapters 3 to 8
Part III

Keep It Running

“Does it stay up and stay good, and will I know when it does not?”

Level 3: Reliability and operations ownerChapters 9 to 13
Part IV

Run It Well

“Can I afford it, and can I change it safely?”

Level 3: Reliability and operations ownerChapters 14 to 16
Part V

Secure and Govern

“Is it safe, and is it allowed?”

Level 4: Program ownerChapters 17 and 18
Part VI

Respond and Run the Program

“What do we do when it breaks, and how does the team run this without heroes?”

Level 4: Program ownerChapters 19 and 20
The role ladder

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.

Level 1

Builder

"It works." The output is checked and the tools are safe.

Part I
Level 2

Quality owner

"It is good, and I can prove it."

Part II
Level 3

Reliability and operations owner

"It stays up, stays good, stays affordable, and changes safely."

Parts III and IV
Level 4

Program owner

"It is secure, governed and recoverable, and it runs without heroes."

Parts V and VI
Chapter map

Twenty-one chapters, from "it works" to "it runs without heroes".

Open 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.

IStepping Into ProductionCan I trust what comes back, and what it does?
  • 00
    You Own It Now

    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.

  • 01
    Anatomy of a Production LLM System

    A model call as a metered function, how it becomes a feature, the agent loop, and a map of twelve ways it fails.

  • 02
    Trusting What the Model Returns and Does

    The validation gateway, a repair loop that stops, tool contracts, and idempotency keys so a retry never pays twice.

IIKnow If It Is GoodIs it any good, and can I prove it?
  • 03
    From Vibe Checks to Evals

    Cases, pass criteria and graders you can trust. Build and run a 30-case eval in plain Python.

  • 04
    Numbers You Can Trust

    Why one run lies: pass@k, standard errors, 95% intervals, the bootstrap and paired comparison.

  • 05
    LLM-as-a-Judge

    Judge prompts with anchored rubrics, five biases that make a judge lie politely, and validating a judge with Cohen's kappa.

  • 06
    Evaluating Agents

    Grade the outcome, not the reply: state checks, trajectories, trigger cases, simulated customers and sandboxes.

  • 07
    Datasets, Labels, and Feedback Loops

    Golden sets, dataset cards, double-labeling, a contamination guard, synthetic data and the feedback flywheel.

  • 08
    Evaluating RAG

    Judge retrieval and generation separately, triage a wrong answer with two questions, and treat chunking as an experiment.

IIIKeep It RunningDoes it stay up and stay good, and will I know when it does not?
  • 09
    When Calls Fail

    Why retries multiply, backoff with jitter, shared retry budgets, deadlines, circuit breakers and step guards.

  • 10
    When Providers Fail

    Routers and adapters, failover that cannot flood the backup, service tiers, streams that die midway, cancellation.

  • 11
    Seeing Inside

    Why status codes miss quiet failures: span types, a tracer in a page of Python, OpenTelemetry and handoffs.

  • 12
    Healthy Means More Than Up

    Golden signals for an agent, SLIs and SLOs, quality SLIs from a judged sample, error budgets and burn-rate alerts.

  • 13
    Catching Quiet Decay

    Baselines and segment-aware bands, three kinds of drift, PSI, chi-square and KS tests, and alert routing.

IVRun It WellCan I afford it, and can I change it safely?
  • 14
    Cost, Latency, and Capacity

    Token economics, FinOps in small pieces, cascades and caching, and how to prove a saving without losing quality.

  • 15
    Prompts as Code, Evals in CI/CD

    Versioned prompts, eval tiers on every pull request, and a non-inferiority gate that blocks or warns.

  • 16
    Releasing and Upgrading Safely

    The release ladder, shadow testing, a self-rolling-back canary, rehearsing failure and the life of a model.

VSecure and GovernIs it safe, and is it allowed?
  • 17
    Securing Agents

    Prompt injection, excessive agency, layered guardrails, risk tiers, and safety evals that report over-refusal too.

  • 18
    Governing Agents

    Least privilege, audit trails, change control, a dated map of the EU AI Act, SOC 2 and NIST (not legal advice), human review.

VIRespond and Run the ProgramWhat do we do when it breaks, and how does the team run this without heroes?
  • 19
    Incident Response and Postmortems

    When to declare, the containment ladder with a kill switch, compensating actions and the blameless postmortem.

  • 20
    Running the Program

    A RACI sheet, on-call and runbooks, readiness reviews and game days, a maturity ladder and a rollout plan.

What you'll make along the way

  • A 30-case eval from your own real failures
  • A validation gateway and a tool contract card
  • A retry policy, an SLO sheet and burn-rate alerts
  • A CI gate for prompt changes, and a canary plan
  • A kill-switch runbook and a blameless postmortem
  • A RACI sheet and a plan for running the program

What it does not cover

  • Training, fine-tuning and self-hosting models
  • Voice and multimodal systems
  • Legal advice (Chapter 18's regulation map is dated and marked as such)
  • Any one vendor's product as "the answer": tools appear as dated examples in skippable Tool Boxes
Inside the book

73 diagrams and charts, 35 of them new.

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.

Diagrams and charts
Companion code

Everything runs offline. No API key. No bill.

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/.

second-edition/ch09_when_calls_fail/retry.py (excerpt)
# 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
0
No key, no network, no cost

Short Python that runs offline, with no API key and no cloud account: a scripted Relay stand-in and a fake clock.

20
One folder per chapter

From a metered model call and a validation gateway to a canary controller, an audit trail and a quarterly program report.

✓
Consistent and tested again

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.

MIT
Free to use in your own work

Open source under the MIT License. The blank templates are in second-edition/templates/; vendor-library snippets live in clearly marked optional/ folders.

Browse the code on GitHub
retries & jittercircuit breakerspass@kCohen's kappaLLM judgeRAG metricstraceparentburn-rate alertsPSI / KS driftnon-inferiority gatecanary rollbackkill switchaudit trailRACI
How to read it

You do not have to read straight through.

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.

Fast path

A busy developer

Ten of the 21 chapters that give you the core: measure, validate, retry, set targets, defend, respond, own.

Chapters 0, 1, 2, 3, 4, 9, 12, 17, 19, 20
Evals first

Quality owners and eval writers

Everything about measuring quality, then drift, CI gates, safe releases and safety evals.

Chapters 0 to 8, 12, 13, 15, 16, then the safety evals in 17
Ops first

Reliability and operations owners

Keep it up first, then measure it, then watch it, change it and respond when it breaks.

Chapters 0, 1, 2, 9, 10, then 3 to 8, then 11 to 16, 19, 20
Back matter you will actually use
APPENDIX A

Production-readiness checklist

Every deliverable in one place, with blocking groups, owners and evidence dates.

APPENDIX B

Templates

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/.

APPENDIX C

Symptom guide

"If something is wrong right now": find the sentence closest to what you see, then what to do first.

APPENDIX D

Formulas and numbers

One row per formula you will want at the desk, each pointing to the chapter that shows the working.

APPENDIX E

Tooling snapshot

The libraries, standards and services the book names, with version, date and status as of 5 October 2026.

APPENDIX F

Regulatory quick map

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.

Good to know

Questions, answered plainly.

How this book was made

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.

Who is this book 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. You need a little Python and a rough idea of an LLM API call. No data-science background is needed.

What is new in the second edition?

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.

Do I need an API key, or to pay for anything, to run the code?

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.

Is it tied to one vendor or framework?

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.

Can I read just the parts I need?

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.

Where are the templates?

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.

Was AI used to write it?

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.

What format is it, and where do I buy it?

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.

Where do I report a mistake?

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.

Portrait of Omar Kamal Hosney
The author

Omar Kamal Hosney

More than thirty years of experience across teaching, software testing, data science and applied AI. He built and led a software testing team; since 2014 the work has been data science and machine learning, and more recently applied generative AI. This book grew out of his three video courses on LLM evaluation, production reliability engineering and AgentOps.

Your LLM feature is live. Now own it.

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