CONCEPT Define measurable success criteria first
You cannot improve a prompt you can't measure. Before iterating, define success criteria that are specific, measurable, achievable, and relevant. Vague goals like "good performance" or "safe outputs" give you nothing to test against; concrete targets do.
⚠️ Unmeasurable
- "Good sentiment analysis"
- "Safe outputs"
- "Accurate answers"
✅ Measurable
- "F1 ≥ 0.85 on 10,000 held-out tweets"
- "< 0.1% of 10,000 outputs flagged toxic"
- "95% of citations resolve to a real source span"
Criteria are usually multidimensional — task fidelity, consistency, relevance, tone, latency, and price often matter at once. State a target for each dimension that's relevant to your app (citation accuracy is critical for a medical tool, minor for a casual chatbot).
CONCEPT Build representative test cases, then iterate empirically
With criteria fixed, build an eval set. Three design principles from Anthropic:
- Be task-specific — mirror your real-world input distribution, and deliberately include edge cases: irrelevant or nonexistent data, overly long inputs, harmful input, and ambiguous cases where humans themselves disagree.
- Automate grading when possible — structure questions for exact-match, string-match, code-based, or LLM-based grading so the suite runs cheaply and often.
- Prioritize volume over perfection — many test cases with slightly noisier automated grading beat a handful of perfectly hand-graded ones.
| Grading method | Good for |
|---|---|
| Exact / string match (code) | Categorical tasks — classification, intent detection |
| Code-based (ROUGE-L, cosine similarity) | Summaries, consistency across paraphrases |
| LLM-based (Likert / binary / ordinal) | Subjective qualities — tone, empathy, PII presence |
| Human grading | Highest-fidelity but slowest; reserve for what can't be automated |
DIAGRAM The empirical prompt-engineering loop
(specific + measurable)"] --> TC["2. Build test cases
(representative + edge cases)"] TC --> EV["3. Build evals
(automate grading)"] EV --> RUN["4. Run prompt vs. eval suite"] RUN --> PASS{"Meets criteria?"} PASS -->|"no"| REF["🟠 Analyze failures,
refine prompt"] REF --> RUN PASS -->|"yes"| VAL["5. Validate on held-out set"] VAL --> SHIP["🟢 Ship + monitor"] classDef ok fill:#d4edda,stroke:#28a745,color:#155724; classDef gate fill:#ffe8cc,stroke:#ff9f40,color:#9a4a0a; class SHIP ok; class REF gate;
CODE An automated grader over a test set
Exact-match grading for a classification task, run over the whole eval set to produce one measurable number you can track across prompt versions:
def exact_match(output, expected): return output.strip().lower() == expected.lower() # eval_set: representative inputs + edge cases + gold labels correct = 0 for case in eval_set: r = client.messages.create(model="claude-opus-4-8", max_tokens=16, messages=[{"role":"user","content": prompt.format(text=case["input"])}]) out = next(b.text for b in r.content if b.type == "text") correct += exact_match(out, case["label"]) accuracy = correct / len(eval_set) # the number you iterate against print(f"accuracy = {accuracy:.3f}") # compare across prompt versions
TRADE-OFFS Automated vs. human grading
| Automated grading | Human grading | |
|---|---|---|
| Cost / speed | Cheap, runs on every change | Slow, expensive |
| Signal quality | Lower per-case, but high volume | Highest fidelity per case |
| Best for | Categorical + code-gradable tasks; regression suites | Nuanced quality the rubric can't capture |
EXAM TRAPS
PRACTICE
Q1 · Rewrite "the classifier should be safe" as a measurable success criterion.
Something specific and quantified, e.g. "Fewer than 0.1% of outputs across 10,000 trials are flagged for toxicity by our content filter." It's specific, measurable, achievable against a benchmark, and relevant to the task.
Q2 · Why deliberately include ambiguous and harmful inputs in your test set?
Because evals must be task-specific and mirror the real input distribution, which includes edge cases: irrelevant/nonexistent data, overly long inputs, harmful input, and cases where humans disagree. Testing only clean inputs hides the failures that actually occur in production.
Q3 · You have 2,000 test cases but only budget to grade a handful by hand. What does Anthropic's guidance say?
Prioritize volume over perfection. Structure the task for automated grading (exact match, code-graded, or LLM-graded) and run all 2,000 — a large suite with slightly noisier grading catches far more regressions than a few perfectly hand-graded cases.