Python evaluation harness
A Python evaluation harness that tests production LLM chat agents
A Python harness that sends scripted conversations to a deployed chat agent, grades every reply with deterministic checks, and fails a safety gate when a reply crosses a line.
How it fits together
Inputs
A private suite of scripted conversations
Safety and quality cases written for one deployed agent, versioned in their own private repository.
A frozen set of reference cases
Hand-written cases with known answers over synthetic data, including prompt injection planted where an agent will read it.
Engine
Harness command line
One Python tool validates the cases, prices a run before it starts, runs it, grades it, and compares the results.
Python
Target adapter
Sends each conversation to the deployed service as a signed request in the service's replay mode, so no real tool fires and no visitor quota is used.
Record and replay
Every model response is recorded, so a run can be replayed later with no key and no network and produce the same report.
Deterministic graders
Code, not a model, decides pass or fail. A grader error fails the run, and every case stays in the total.
Safety gate
A forbidden action, a followed injection, or a leaked secret fails the gate, whatever the other scores say.
Outputs
A report with a gate verdict
Pass rates by grader, the cases that changed between two prompt versions, and how much one prompt disagrees with itself across repeated runs.
Findings for a person to act on
Each failed check names the conversation and the rule it broke. A person decides what to change.
Guardrails
- Replay is the default, and a live run needs a typed confirmation
- Spend and call limits are reserved before each call, not checked after
- A private suite and its recordings never enter the harness repository
The problem
A chat agent that answers the public can be wrong in ways a unit test never sees. It can follow an instruction hidden in the text it reads, promise something the business does not offer, or change its behavior after a small prompt edit. Reading a few transcripts by hand does not catch that, and the same prompt can give a different answer on the next run. I needed a way to measure an agent against written expectations, repeat the measurement exactly, and do it without an open-ended bill.
What I built
- A command-line harness in Python that loads hand-written cases, runs a tool-using agent against them, and grades the result.
- Deterministic graders for tool use, cause, evidence, fabrication, recommended action, and injection, with a safety gate that fails the run on any forbidden action or leaked secret.
- A final set of cases frozen by a hash manifest, a fingerprint pinned in code, and a git tag, so any later edit to the cases is visible.
- Record and replay: one agent loop runs against a live model, a fake, or a recording, and replay stops without making a request if anything differs from what was recorded.
- Cost controls in code: limits on turns, retries, tokens, and spend, a ledger that reserves the cost of each call before it is made, and a command that prices a run without calling a model.
- A target adapter that sends scripted conversations to a deployed chat service and grades the replies, with its own limits on calls and pacing.
How I built it
The harness is original Python with typed models in Pydantic and a test suite in pytest. Cases are plain TOML files a person can read and review. The reference study runs Claude through the API and compares two versions of a prompt across repeated runs, because a single run of each can tell a different story each time. The deployed-agent adapter uses only the Python standard library for its HTTPS calls, never follows a redirect, and never retries. Every design decision is written down in the repository beside the code it explains.
How it runs in production
The harness tests a chat agent that is deployed and answering visitors on a multi-tenant platform. A private suite of safety and quality conversations runs against the live service through the target adapter. Requests are signed, and the service handles them in a replay mode that turns tools off, so a test can never create a real lead or use up a visitor's quota. That also sets the limit of what it checks: it grades the agent's replies, not its tool calls.
The first run against production returned findings, and each one went to a person as a named conversation and a broken rule. The suite is a regression check. It is rerun when the agent's prompt, knowledge base, tools, or model changes, and a live run starts only after a person confirms it. The same adapter can point at any other deployed agent that offers a replay mode.
What it shows
I measure agents the way I test software: written expectations, checks that run the same way every time, a hard gate on safety, and a spending limit set in code. I build that tooling in Python, and I report what a run measured and what it did not.