~/academy $ claude learn evaluating-your-claude-app
Evaluate your Claude app before you ship
How to build a small test set for a Claude-powered feature, grade outputs with code or an LLM judge, and compare prompts, models and effort levels before shipping. 8 min
$ Read
Decide what good looks like
The docs call a good evaluation set the most important step in choosing or changing a model. Start with success criteria that are specific and measurable. Not 'answers well', but 'routes at least 95 percent of test tickets to the right queue' or 'never quotes a refund outside the 30-day policy'.
Cover the things that matter for your feature: accuracy, tone and style, consistency, use of the context you supplied, privacy, latency and price. You will rarely need all of them, but name the ones you do.
Lesson notes: Evaluate your Claude app before you ship
Everything in this lesson as text, for revision or to read without the interactive steps. By the end you will be able to: You build a repeatable test that scores your feature, so prompt or model changes are decided by evidence.
Step 1 of 7 · Read
Decide what good looks like
The docs call a good evaluation set the most important step in choosing or changing a model. Start with success criteria that are specific and measurable. Not 'answers well', but 'routes at least 95 percent of test tickets to the right queue' or 'never quotes a refund outside the 30-day policy'.
Cover the things that matter for your feature: accuracy, tone and style, consistency, use of the context you supplied, privacy, latency and price. You will rarely need all of them, but name the ones you do.
Step 2 of 7 · Read
Build a small test set
Make the cases look like real traffic, using anonymised examples from your own users where you can. Then add the edge cases: irrelevant questions, very long inputs, hostile or abusive messages and genuinely ambiguous requests.
Automate grading wherever possible. The docs favour volume: many cases with slightly rougher automatic grading beat a handful of perfectly hand-graded ones. Keep the set in a file so every run uses the same cases.
tests.jsonl {"input": "My parcel ORD-10442 never arrived", "expected_queue": "delivery"} {"input": "Can I change the email on my account?", "expected_queue": "account"} {"input": "Your product is rubbish and so are you", "expected_queue": "complaints"} {"input": "What is the capital of Peru?", "expected_queue": "out_of_scope"}Step 3 of 7 · Read
Grade with code first, then an LLM
Code grading is fastest and most reliable: exact match (
output == expected) or string match (key_phrase in output). Use it for labels, fields and anything with one right answer. Human grading is the most flexible but slow and expensive, so keep it for spot checks.LLM grading handles judgement calls such as tone or whether a summary covers the key points. Give the grader a detailed rubric, ask for a fixed output ('correct' or 'incorrect', or a 1 to 5 score), and leave thinking on so it reasons before scoring. The docs suggest grading with a different model from the one that wrote the answer. Ask for a short explanation, not step-by-step reasoning, which can trigger a refusal.
A structured LLM grader from typing import Literal from pydantic import BaseModel import anthropic client = anthropic.Anthropic() class Grade(BaseModel): verdict: Literal["correct", "incorrect"] explanation: str def llm_grade(answer, rubric): prompt = f"""Grade the answer against the rubric. <rubric>{rubric}</rubric> <answer>{answer}</answer> Give a verdict and a one-sentence explanation.""" r = client.messages.parse( model="claude-sonnet-5-5", # a different model from the one under test max_tokens=4096, output_format=Grade, messages=[{"role": "user", "content": prompt}], ) return r.parsed_outputStep 4 of 7 · Read
Compare prompts, models and effort
Run the same test set through each variant you are considering: prompt A against prompt B, Opus 5.5 at medium effort against Sonnet 5.5 and Haiku 5.5, or several effort levels on one model. Record the score, the cost from
usageand the time taken for each. Judge cost per correct answer, not per request.Large evaluation runs suit the Batches API, which halves the price. Re-run the set whenever you change the prompt, the model or the effort level, and add every real failure you find in production as a new test case.
Compare three models import json, time tests = [json.loads(line) for line in open("tests.jsonl")] for model in ["claude-opus-5-5", "claude-sonnet-5-5", "claude-haiku-5-5"]: correct, start = 0, time.time() for t in tests: label = route_ticket(t["input"], model=model) # your feature correct += label.strip().lower() == t["expected_queue"] print(model, f"{correct}/{len(tests)}", f"{time.time() - start:.1f}s")Step 5 of 7 · Improve a prompt
Write a grading prompt
You need an LLM judge to check whether customer service replies follow your refund policy. Rewrite the weak grader prompt so its verdicts are consistent and easy to count.
Starting prompt:
Is this reply good? Answer yes or no.
Hint: Give the policy, list exactly what makes a reply pass or fail, say what to output, and ask for a short explanation.
Show a strong version
You are grading a customer service reply against our refund policy. <policy>Refunds are allowed within 30 days of delivery for unused items. Opened software is not refundable. Staff must never promise a refund outside these rules.</policy> <reply>{reply}</reply> The reply is CORRECT only if all of these are true: 1. It does not promise or imply a refund the policy does not allow. 2. If a refund is allowed, it states the 30-day limit. 3. It is polite and offers a clear next step. If any rule is broken, the reply is INCORRECT. Output a verdict of 'correct' or 'incorrect' and one sentence naming the rule that decided it.Step 6 of 7 · Sort
Which grader fits?
Decide how each success criterion should be graded.
- The ticket was routed to the right queue label
- The JSON output has every required field
- The reply is polite and empathetic
- The summary covers the three main risks in the report
- The answer includes the order number
- The writing matches your brand voice guide
Show the answers
- The ticket was routed to the right queue label: Code can grade it. One correct label, so an exact match works.
- The JSON output has every required field: Code can grade it. Parse it and check the keys. Structured outputs make this nearly automatic.
- The reply is polite and empathetic: Needs an LLM or a person. Tone needs judgement. Use an LLM grader with a clear rubric or scale.
- The summary covers the three main risks in the report: Needs an LLM or a person. Coverage of ideas, not exact words, needs a judge.
- The answer includes the order number: Code can grade it. A simple string match does it.
- The writing matches your brand voice guide: Needs an LLM or a person. Style is a judgement call. Give the grader the guide as its rubric.
Step 7 of 7 · Quiz
Check your understanding
You are about to test whether Sonnet 5.5 can replace Opus 5.5 in your feature. What do you do first?
- Switch production over and watch the complaints.
- Try ten prompts by hand and go with your gut.
- Write measurable success criteria and a test set of real and edge cases, then run both models through it.
Show the answer
Write measurable success criteria and a test set of real and edge cases, then run both models through it. The docs put a good evaluation set first. Then compare accuracy, edge cases and cost side by side.