Guides · Series · 18 parts

Harness Engineering for Production AI Systems

The harness is a control system. Every component in it is a sensor, a comparator, a gate, or a bound — and anything else is application code.

Harness Engineering for Production AI Systems cover

The book

Harness Engineering for Production AI Systems

Sensors, Gates, and Bounds for LLM Applications That Have to Work When the Model Doesn't

Build the control layer around your LLM application: sensors that observe, comparators that check, gates that decide, and bounds that cap.

Four roles, and nothing else

Most writing about making LLM applications reliable is a list of techniques: validate the JSON, add a retry, put a human in the loop. Lists do not tell you what is missing. This series starts from a different claim — the harness around a model is a control system, and every component in it plays exactly one of four roles. A sensor observes. A comparator checks an observation against a standard. A gate decides whether a proposal becomes an action. A bound caps how far the system can go. If a component is none of these, it is not harness.

That claim is useful because it is checkable. Classify every component you have, and the gaps show up as roles nobody fills: a gate with no comparator behind it, a bound that only records spending after it happens, a sensor whose signal no one reads.

One agent, seventeen chapters

Every part follows the same system: a billing support agent for a mid-size B2B software company, running in two modes — copilot, with a human in the loop on every reply, and queue-drain, working the backlog overnight with nobody watching. It can read tickets and invoices, and it can post replies, apply credits, and issue refunds. Each part takes one chapter of the book, names the failure that chapter exists to prevent, and argues one position about it.

This is the book-length treatment. The earlier eight-part Harness Engineering series covers several of the same layers more briefly; this one goes chapter by chapter, adds the parts that series never reached — signals, cost bounds, authority bands, testing and attributing failures — and ends with the chapter on where the harness meets the framework.

Which part solves my problem

The series reads in order, but if something is already broken, start here.

  • “The demo worked and production does not, and the fix everyone proposes is a better model.”Part 1 →
  • “I cannot say which of my components actually decides anything.”Part 3 →
  • “The agent’s own earlier reply came back inside a customer ticket and was treated as the customer’s words.”Part 4 →
  • “Context compaction dropped a rule out of the system prompt thirty turns in.”Part 5 →
  • “A model upgrade changed the output format and the validator now rejects everything — and nobody can say which layer failed.”Part 16 →
  • “The provider returned 503 for four minutes and the agent retried into a storm.”Part 8 →
  • “The model proposed a refund for an amount that appears on no invoice.”Part 9 →
  • “A knowledge-base article carried an instruction addressed to the agent, and every gate passed it.”Part 11 →
  • “The process restarted and I cannot tell which side effects already happened.”Part 12 →
  • “Unattended mode quietly inherited the authority of the supervised mode.”Part 14 →
  • “The circuit breaker stuck open and nobody noticed, because escalation looks like success.”Part 17 →

The series

18 of 18 published

Part1
Book Ch 1

Harness Engineering Without an Oracle: What Transfers

The famous harness results were scored by tests your agent does not have. The hook transfers once you move it in front of the action. The oracle its check read stays behind.

Part2
Book Ch 2

LLM Trust Boundaries: Draw Them by Reach, Not by Author

Your system prompt, your runbook and your own tool results reach the model the same way a customer's ticket does. A rule written there is a measured habit of the model, not a control.

Part3
Book Ch 3

LLM Guardrails That Stop Nothing: The Role Test

A guardrail counts only if the action can fail because of it. Classify every component by that power, then make CI fail when a verdict has nothing that can refuse on the other end.

Part4
Book Ch 4

LLM Input Validation: Judge the Record, Not the Clean Input

The input failure no detector is built for needs no attacker: your own words come back under a customer's label. Split the entry point into a sensor that records what it changed and a gate that never cleans.

Part5
Book Ch 5

LLM Context Window Management: The Policy Nobody Wrote

Every fit-to-window loop runs a policy nobody wrote, and its quietest failure is a constraint summarised into a sentence that constrains nothing. Give the context budget a floor, and refuse below it before the model is called.

Part6
Book Ch 6

AI Agent Decision Logs: Catch the Refund No Control Decided

Traces and decision logs record the checks that ran. Neither can show the check that should have run and never did, until the harness declares which decisions each action is owed.

Part7
Book Ch 7

LLM Output Repair: A Re-ask That Passes Can Still Be a Guess

Re-asking with the validation error is safe for a broken JSON shape. Send a content correction back and the model learns what passes, so the next pass no longer says the answer is right.

Part8
Book Ch 8

LLM Fallback Models Inherit Authority They Never Earned

One gateway can check that the prompt fits the fallback model. None I found checks whether that model may issue the refunds your agent was allowed to make on the primary, or counts the requests it spends while it does.

Part9
Book Ch 9

AI Agent Approval Gates: Failed Checks Must Never Widen

Send every failed guardrail check to a human, and in a mode with no reviewer the suspicious refund becomes one somebody may approve while its clean twin is refused.

Part10
Book Ch 10

Strict Tool Schemas Aren't Enough: Narrow LLM Tool Calls

A strict schema makes a refund call well-formed. It does not stop the model from choosing the account and the amount, and every check after it is judging those choices.

Part11
Book Ch 11

Indirect Prompt Injection: Tool Calls Don't Say Who Asked

Once a tool is narrowed, an injection no longer needs a wrong value. It needs a real one that someone other than the customer chose, and no check that reads only the proposal can tell who chose it.

Part12
Book Ch 12

LangGraph Interrupt Resume: Approvals Run on Stale Facts

A human approval is a checkpoint resume. It restores what the agent read before the pause, and the world kept moving while the reviewer was away.

Part13
Book Ch 13

AI Agent Spend Limits Pay for the Call That Crosses Them

A budget checked against what the run has already spent fires one unit late. Reserve the declared worst case of the next call, refund or fan-out before it runs, and settle the real cost after.

Part14
Book Ch 14

Earned Autonomy for AI Agents: What a Track Record May Widen

A clean month tells you how often the agent is wrong, not what being wrong costs. Let good behaviour widen throughput, and hold the two numbers that consequence sets.

Part15
Book Ch 15

Testing AI Agent Guardrails: Green Suites Hide Dead Controls

An adversarial suite proves that something refused each bad output. It does not prove that the control claiming that output works, and two ordinary things hide the difference.

Part16
Book Ch 16

AI Agent Failure Attribution: Why the Model Gets the Blame

My book's attribution protocol never clears a layer on a missing record. It convicted the model with four questions unanswered, and its own test suite pins the behaviour.

Part17
Book Ch 17

AI Agent Guardrail Monitoring: A Refusal Is Not Proof of Life

My book's readiness check says GO on both of its own incidents: a gate that refused 406 tickets in one night, and a ceiling that a reviewed refactor stopped counting.

Part18
Book closer

LangGraph Guardrails: A Node That Skips the Executor

The same refund, on an invoice the customer does not own, is refused by my book's executor and paid by its LangGraph graph, and neither an import test nor a tool-name grep can see why.

The companion code

The companion repo builds the harness for one billing support agent, one git tag per chapter. Every tag passes its test suite with no API key, no network, and no model — the harness is tested as a control system, not as a prompt.

View the companion repository on GitHub →

Other guide series

GenAI Architectures

There are eight architectures and seven boundaries between them. Every boundary is a yes-or-no question about the task — not a judgment call about the design.

Chat Templates

A chat template is the contract between your messages and the exact token stream the model was trained on. Get it wrong and nothing raises — the model just gets quietly worse.

Agentic AI with LangGraph

An eight-part guide to the part of agent engineering nobody demos: making the thing survive a restart, a concurrent write, a bad tool call, and a Tuesday deploy.

Harness Engineering

AI systems do not fail at the model layer. They fail in the code around it — and that code is a designable layer with its own architecture.

RAG Engineering

Most RAG failures happen upstream of the LLM, accumulate invisibly, and only surface as an incident. This series names each one.

Claude Code Playbook

Claude Code has four layers — context, skills, subagents, hooks — and the variable that decides which one you need is enforceability, not capability.

AI Control Plane

A fleet of agents needs a layer that is not itself an agent — observability, policy, orchestration, versioning, cost, and audit, built as infrastructure.

Agentic AI in the Data Center

In physical infrastructure, an agent’s autonomy is capped by reversibility and jurisdiction — not by how good the model is.

Codebase to Architecture Doc

A three-pass methodology for compressing any codebase into validated diagrams and decisions — and then a LangGraph pipeline that runs it for you.

Federated AI Agents

Every call that crosses from one owner to another is a seam, and a seam has five properties — contract, authority, state, failure, and accountability — that are free inside one deployment and have to be built across it.

Books by Ranjan Kumar

Federated AI Agents cover

Federated AI Agents

Right-Sized AI cover

Right-Sized AI

Harness Engineering for Production AI Systems cover

Harness Engineering

The 7 GenAI Architectures cover

The 7 GenAI Architectures

Building Real-World Agentic AI Systems with LangGraph cover

Building Real-World Agentic AI Systems

The ChatML Handbook cover

The ChatML Handbook

The Chat Templates Handbook cover

The Chat Templates Handbook