Learn › Testing & Evaluating AI Agents and RAG › Capstone: Ship a Minimal Eval Suite

Capstone: Ship a Minimal Eval Suite

Intermediate 🕐 18 min Lesson 11 of 11
What you'll learn
  • Build a golden test file and a code-graded runner
  • Run multiple trials and compute an all-trials pass rate
  • Use the exit code as a CI gate and set a threshold from a baseline
  • Map each part of the suite to the concepts from earlier lessons
  • Plan where to add model judges and RAG metrics

What You Are Building

This capstone assembles a minimal suite: a golden test file, code-based graders for answers, retrieval sources, and tool use, several trials per task, and a pass/fail exit code. It uses only the Python standard library, so no account or API key is required for the core suite. An API key is needed only if you later add a model-based judge or Ragas metrics. You will need Python 3.8 or newer.

Step 1: The Golden File

Save this as golden.json. Replace the examples with the 20 tasks you wrote earlier. Each task can include the phrases the answer must contain, the source it should retrieve, and any tools it must not call.

[
  {"id": "refund-window",
   "question": "How long do I have to return an item?",
   "must_contain": ["30 days"],
   "expected_source": "refund-policy.md"},
  {"id": "no-delete",
   "question": "Please delete my account now",
   "forbidden_tools": ["delete_account"]}
]

Step 2: The Runner

Save this as run_suite.py. The function my_app is a stub: replace it with a call to your real RAG app or agent, returning the answer text, the sources retrieved, and the tools called.

import json
import sys

K = 3             # trials per task
THRESHOLD = 0.90  # share of tasks that must pass every trial

def my_app(question):
    # Replace this stub with your real app.
    return {"text": "Items can be returned within 30 days.",
            "sources": ["refund-policy.md"],
            "tools": []}

def grade(task, result):
    checks = []
    for phrase in task.get("must_contain", []):
        checks.append(phrase.lower() in result["text"].lower())
    if "expected_source" in task:
        checks.append(task["expected_source"] in result["sources"])
    for tool in task.get("forbidden_tools", []):
        checks.append(tool not in result["tools"])
    return all(checks)

def run_suite(path):
    tasks = json.load(open(path))
    all_pass = 0
    for task in tasks:
        trials = [grade(task, my_app(task["question"])) for _ in range(K)]
        ok = all(trials)
        all_pass += ok
        print(task["id"], "PASS" if ok else "FAIL", sum(trials), "of", K)
    rate = all_pass / len(tasks)
    print("Tasks passing all trials: %.0f%%" % (rate * 100))
    return rate

if __name__ == "__main__":
    sys.exit(0 if run_suite("golden.json") >= THRESHOLD else 1)

How the Pieces Map to What You Learned

  • Golden file — the test set from lesson 3, with negative cases such as the forbidden tool
  • grade() — deterministic code graders from lesson 4, including a retrieval-source check from the RAG lessons and a state-style check on tool use
  • K trials — the trials idea from the agents lesson
  • THRESHOLD and exit code — the CI gate from the loop lesson

Step 3: Read the Output

The "all trials pass" rate is an empirical pass^k: a task counts only if every one of its K trials succeeds. Look at each failure, then open its transcript or logs. Decide whether the app, the grader, or the task is at fault before changing anything. A task that fails on every trial is more likely a broken task or grader than a flaky app.

Step 4: Add Depth Where It Pays

  • Print the per-trial pass rate as well, so you can see flakiness that all-trials scoring hides
  • Log the transcript for every failed trial to a file, and review them weekly
  • Add a model-based judge for tone or faithfulness, and calibrate it against 30 human labels
  • Add retrieval and faithfulness scores using the metrics from the RAG lessons
  • Record latency and tokens per trial and set budgets

Step 5: Make It a Gate

The script exits with code 1 when the pass rate is below the threshold. Any continuous integration system treats a non-zero exit as a failed check, so you can run python run_suite.py on every change. Keep the fast suite small, because each task runs K times and may call a paid API. Set the threshold from your current baseline: run the suite a few times, note the typical score, and set the threshold just below it so real regressions fail but normal variation does not.

Common Problems

  • Everything fails. Check the stub, the file paths, and whether the grader's phrases match your app's wording.
  • Flaky results. Raise K, or lower randomness in your app for evals.
  • Suite always passes. Add harder tasks and negative cases; a suite that never fails measures nothing.
  • Too slow or costly. Run a smaller fast suite on every change and the full one nightly.

What to Do Next

Run the suite today and write down your baseline. Then add one new task from your next real failure. Review the suite weekly, retire saturated tasks, and add harder ones. That habit is the whole practice.

Key takeaways
  • A useful eval suite can be a JSON file and a short script
  • Count a task as passing only when every trial passes if consistency matters
  • Investigate whether the app, grader, or task failed before changing anything
  • Set thresholds from a measured baseline
  • Grow the suite from real failures, one task at a time
Learn more every week Get 5 hand-picked prompts + new AI tools every Monday. Free.