Scope the app & write the eval set first
A problem statement, success criteria and a 30-example eval set before writing app code.
By Invicly Tech, , in AI Engineering with Python. About 12 minutes to read.
In short
Before writing app code, define the problem, what success looks like and a small eval set. The eval set becomes your scoreboard, so every design choice afterwards can be measured.
Explained simply
Most AI side projects fail in the same way. Someone starts coding a chatbot, it gives a few nice answers in a demo, and then nobody can say whether it is actually good. This topic stops that from happening. Before you write any app code, you decide what the app is for and how you will measure it.
You write three short things. A problem statement says who the users are and what they need help with. Success criteria are numbers that say when the app is good enough, such as "85% of answers correct". An eval set is a list of test questions with the answers you expect.
The eval set is like the exam you write before you study. Because it exists before the app, you cannot accidentally choose easy questions that your app already passes. Every later choice, a new chunk size, a different prompt, another model, gets scored against the same exam.
Finally, you sketch the architecture: the parts of the system and how a question flows through them. Keep it simple. The first version only needs to answer questions with sources. Extras come later, and only if the scores say they help.
Press Play on a diagram to walk through it one step at a time.
- Step 1Problem statement
Who the users are and what they need
- Step 2Success criteria
Measurable targets like 85% correct answers
- Step 330-case eval set
Real questions, edge cases and refusals
- Step 4Architecture plan
Ingest, retrieval, tools, API and deployment
- 20 typical
- Real user questions
- Answer is in one document
- Common phrasing and typos
- 6 edge cases
- Answer spread over two docs
- Recently changed policy
- Vague or very short question
- 4 refusals
- Out of scope topic
- Answer not in any document
- Request the app must not do
In depth
A problem statement you can test
A good problem statement is narrow and concrete. It names the users ("support agents in their first month"), the job ("answer billing questions from our help center and policy docs"), and today's pain ("they search three tools and still escalate 30% of tickets"). It also lists the sources the app may use, because a RAG app can only be as good as its documents.
Just as important is what the app will not do. Write a short list of non-goals: no legal advice, no account changes, no questions about other products. Non-goals turn into refusal cases in your eval set, and they keep the project small enough to finish.
Add constraints you already know: data that must stay private, a maximum cost per question, a language the users need. A reviewer should be able to read the page in two minutes and know exactly what "done" means.
- Users: who, and how they ask today
- Job: the one thing the app helps with
- Sources: which documents it may read
- Non-goals: what it must refuse
Success criteria: quality, refusals, speed and cost
Every criterion should be a number you can compute from an eval run or from logs. Vague goals like "accurate" or "fast" cannot fail, so they cannot guide you.
Cover four areas. Quality: the share of answers judged correct, and the share whose citations really support the answer. Refusals: out-of-scope questions should get a polite refusal, ideally 100% of them. Latency: use p95, the time under which 95% of requests finish, because averages hide slow outliers. Cost: dollars per question, computed from input and output tokens times your provider's current prices.
Also write down a baseline to beat. What does the existing search box or a plain prompt without retrieval score on the same eval set? If your RAG app cannot beat that, the extra complexity is not earning its keep.
- Quality
- At least 85% judged correct
- At least 90% citations valid
- Safety
- 100% refusal on out-of-scope
- No made-up sources
- Speed
- p95 latency under 6 s
- First token under 2 s when streaming
- Cost
- Under $0.01 per question
- Monthly budget alert set
Building the 30-case eval set
Collect real questions first: support tickets, chat logs, Slack threads, or ask five future users to write what they would type. Real questions are messier than the ones you would invent, and that is the point. Then add edge cases: vague questions, typos, questions whose answer is split across two documents, questions about recently changed policies. Finally add out-of-scope questions the app must refuse.
For each case store the input, the key facts a correct answer must contain, the IDs of the documents that hold the answer, and a few tags such as "edge" or "refusal". Save it as JSONL (one JSON object per line) in the repository so it is versioned with the code.
Thirty cases is a starting size, not a statistic. Each case is worth about 3.3 percentage points, so moving from 80% to 83% is one case and may be noise. Grow the set over time by adding every real failure you see.
- Mix used here: 20 typical, 6 edge, 4 refusal
- Store expected facts, not one exact sentence
- Store expected document IDs to test retrieval alone
- Version the file: evals/cases.jsonl
Deciding how each case is scored
Decide the scoring before the app exists, or you will be tempted to pick whatever scores well. Use the cheapest reliable check for each property.
Code checks are free and exact: does the answer cite at least one source, are all cited IDs among the chunks you actually sent, did a refusal case get refused. Retrieval can be scored on its own: recall@5 asks whether at least one expected document appears in the top 5 retrieved chunks. That tells you if a failure came from search or from the model.
Correctness of free text needs judgement. An LLM judge with a short rubric ("PASS if the answer states all key facts and says nothing that contradicts them") scales well, but it can be wrong. Grade 10 to 15 cases by hand and compare. If you and the judge disagree often, fix the rubric before you trust its numbers.
- 1Run the app
Save answer, sources, latency, tokens
- 2Retrieval check
Expected doc in the top 5?
- 3Code checks
Cited IDs valid, refusal when required
- 4Judge correctness
Rubric against the key facts
- 5Record result
Pass or fail plus a short reason
Planning the architecture
Draw the path one question takes: the API receives it, retrieval finds chunks, the model writes an answer with citations, and the API returns the answer and its sources. Next to it, draw the offline path: load documents, split them into chunks, embed them and store them, for example in Postgres with pgvector.
For each box, pick the simplest option that could work and write down why. One embedding model, vector search with k = 5, one prompt, one model. Plan the tool you will add later, but do not build it on day one.
Do a rough cost check now. A RAG prompt with 5 chunks of about 500 tokens plus instructions is roughly 3,000 to 4,000 input tokens. Multiply by your provider's price per token, add the output tokens, and compare with your budget. If the number is far too high, you will want a smaller model or fewer chunks, and it is better to know before you build.
Learn it in 4 short steps
About 45m each. Track them with a timer in your plan.
- 1Write the problem statement~45m
- 2Define success criteria~45m
- 3Build a 30-example eval set~45m
- 4Plan the architecture~45m
Key points
- A narrow, well-defined problem beats a vague general assistant.
- Success criteria should be numbers you can measure with the eval set.
- Write eval cases before code so you are not grading your own homework.
- Include out-of-scope questions the app should refuse.
Key terms
Tap a card to flip it. 0/4 known
Examples
Problem: New engineers cannot find answers in 400 pages of internal docs.
Users: Engineers in their first 3 months.
Success:
- 85% of eval answers correct and cited
- 100% refusal on out-of-scope questions
- p95 latency under 6 seconds
- Under $0.01 per question
Eval set: 30 cases (20 real, 6 edge, 4 refusal)A one-page scope with measurable success criteria.
Turning a vague idea into a one-page scope
The idea: "an AI bot for our docs". Step 1: pick one user group and one job, here new support agents answering billing questions. Step 2: name the sources, the help center and the refund policy, and write non-goals. Step 3: turn wishes into numbers: "good answers" becomes 85% judged correct with valid citations, "safe" becomes 100% refusals on the 4 out-of-scope cases. Step 4: record the baseline: the current keyword search finds the right article for 12 of 30 questions.
Users: support agents in their first month
Job: answer billing and refund questions with sources
Sources: help center (220 articles), refund policy PDF
Non-goals: legal advice, changing accounts, other products
Success: >= 85% correct, >= 90% citations valid,
100% refusals on out-of-scope, p95 < 6 s, < $0.01/question
Baseline: keyword search finds the right article for 12/30
Eval set: evals/cases.jsonl, 30 cases (20 typical, 6 edge, 4 refusal)Writing and sanity-checking eval cases
Each line of the JSONL file is one case. Step 1: give every case an ID, the question, the key facts and the expected document IDs. Refusal cases have no facts and no documents, and a flag says the app must refuse. Step 2: load the file with a Pydantic model so a typo in a field name fails loudly instead of silently skipping a check. Step 3: print the mix by tag to confirm it matches the plan before any app code exists.
import json
from collections import Counter
from pydantic import BaseModel
class Case(BaseModel):
id: str
question: str
key_facts: list[str] = []
expected_docs: list[str] = []
must_refuse: bool = False
tags: list[str] = []
cases = [Case.model_validate(json.loads(l)) for l in open("evals/cases.jsonl")]
print(len(cases), Counter(t for c in cases for t in c.tags))Quick reference
- Problem statement = users + job + sources + non-goals + known constraints
- Every success criterion must be a number computed from evals or logs
- Report p95 latency, not the average
- 30 cases: each case is about 3.3 points, so 1 or 2 cases of change can be noise
- Store key facts and expected doc IDs per case, not one exact answer
- recall@5: is an expected document among the top 5 retrieved chunks?
- Check your LLM judge against 10 to 15 hand-graded cases
- Measure a baseline (plain search or no retrieval) on the same eval set
Common mistakes
- Scoping a do-everything assistant that cannot be evaluated.
- Writing success criteria that cannot be measured, like users love it.
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Rewrite these goals as measurable success criteria: "answers should be accurate", "it should be cheap", "it should not make things up".
- Exercise 2medium
Write 3 JSONL eval cases for a docs assistant: one typical, one edge case, one refusal.
- Exercise 3hard
Write score_case(case, result) returning a dict of checks: retrieval hit in the top 5, all cited IDs valid, and refusal correct. result has retrieved_ids, sent_ids, cited_ids and refused.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- How many eval cases do I need?
- Thirty is enough to start and to catch big regressions. Grow it to 100 or more over time by adding every real failure, because small sets cannot detect small improvements.
- Can I use an LLM to generate my eval questions?
- It can help with variety, but base the set on real user questions first. Generated questions tend to match the documents' wording too closely, which makes retrieval look better than it is.
- What if I do not have real users yet?
- Ask a few people from the target group to write questions they would really ask, and mine old tickets, forum posts or search logs. Even 10 real questions are worth more than 50 invented ones.