By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
Tests in Lesson 12 prove the plumbing: the tool was called, the approval stayed pending, the trace had the right order. They cannot tell you whether the answer was any good. An eval set measures the product. Build a small, versioned set of real support questions with the facts a correct answer must contain, the tool path it must take, and the things it must never do. Twenty cases catch a broken prompt; a few hundred let you compare models.
Start from tickets, not from imagination. Each case needs three things: a question, the expected tool trajectory, and the answer properties — required facts, forbidden claims and an acceptable shape. Record why the case exists; a case added after an incident is worth more than ten invented ones.
The scoring functions are ordinary Python and should stay that way: exact match for IDs, statuses and dates; contains for required facts; trajectory checks for tool names, arguments and order; explicit safety checks for writes. Prose is not a string to compare — it is a set of claims to verify. Keep every scorer small enough to unit-test itself.
def contains_score(answer: str, must_contain: tuple[str, ...]) -> float:
"""Fraction of required facts present in the answer (case-insensitive)."""
if not must_contain:
return 1.0
answer = answer.lower()
found = sum(term.lower() in answer for term in must_contain)
return found / len(must_contain)
def trajectory_ok(used: list[str], expected: tuple[str, ...]) -> bool:
"""Did the agent call exactly the expected tools, in order?"""
return tuple(used) == expected
CASES = [
{
"question": "Where is order #4521?",
"answer": "Order #4521 was delivered on Tuesday and contains a ceramic mug.",
"must_contain": ("4521", "delivered"),
"used_tools": ["lookup_order"],
"expected_tools": ("lookup_order",),
},
{
"question": "Can I return a damaged mug?",
"answer": "Yes - damaged items are refunded or replaced within 30 days.",
"must_contain": ("30 days", "shipping address"),
"used_tools": ["search_docs", "create_replacement"],
"expected_tools": ("search_docs",),
},
]
scores: list[float] = []
for case in CASES:
contains = contains_score(case["answer"], case["must_contain"])
tools_ok = trajectory_ok(case["used_tools"], case["expected_tools"])
scores.append(contains)
print(
f"{case['question']} contains={contains:.2f} tools_ok={tools_ok}"
)
mean_contains = sum(scores) / len(scores)
suite_passed = mean_contains >= 0.9 and all(
trajectory_ok(case["used_tools"], case["expected_tools"]) for case in CASES
)
print(f"mean_contains={mean_contains:.2f}")
print(f"suite_passed={suite_passed}")order_id, item) from result['messages']; a correct-looking answer fetched by the wrong tool is still a bug.Keep the fast suite keyless: script the fake model's turns for the trajectory cases, score the final text with the same functions, and run it on every pull request that touches prompts, tools or agent code. Keep a separate live-model suite for quality, run it on a schedule or before a release, and compare its report with the previous run instead of failing on one noisy sample. A regression suite that blocks merges must be cheap and deterministic, or the team will disable it.
# eval_runner.py — run in CI with: python eval_runner.py
import sys
from langchain.messages import HumanMessage
from support_agent.agent import build_agent
from support_agent.eval import CASES, contains_score, trajectory_ok
THRESHOLD = 0.9
def evaluate(agent) -> tuple[float, bool]:
"""Return the mean contains score and whether every trajectory matched."""
scores: list[float] = []
tools_ok = True
for case in CASES:
result = agent.invoke(
{"messages": [HumanMessage(case["question"])]}
)
messages = result["messages"]
answer = messages[-1].text
used = [message.name for message in messages if message.type == "tool"]
scores.append(contains_score(answer, case["must_contain"]))
tools_ok = tools_ok and trajectory_ok(
used, case["expected_tools"]
)
return sum(scores) / len(scores), tools_ok
if __name__ == "__main__":
# In CI, build_agent is passed a scripted fake model, so no key is needed.
mean, tools_ok = evaluate(build_agent())
print(f"mean_contains={mean:.2f} tools_ok={tools_ok}")
sys.exit(0 if mean >= THRESHOLD and tools_ok else 1)| Metric | Question it answers | CI gate |
|---|---|---|
| Exact match | Did the structured value come back exactly? | IDs, statuses and dates: 100% |
| Contains | Are the required facts in the answer? | Mean above a threshold such as 0.9 |
| Trajectory | Were the right tools called in order? | Every case, hard failure |
| Safety invariant | Did a write stay pending? | Every case, hard failure |
| Cost and latency | What did each case spend? | Reported, alert on regression |
Key takeaways
An eval set of real tickets is the regression suite for answer quality, tool trajectory and safety.
Score with plain Python: exact match for structured values, contains for required facts, trajectory checks for tools and order.
Keep the CI suite keyless and deterministic with fake models; run live-model quality evals on a schedule and compare reports.
Gate merges on safety and trajectory, threshold the quality score, and add a case every time production is wrong.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.