Lesson 4 of 5 in Prompt Engineering & Structured Output
3.4 · Evaluation — how you know it works
Prompt engineering without eval is guessing. This lesson covers building the held-out eval set, choosing grading strategies (exact-match, rubric, human), tracking regressions across changes, and the anti-patterns that make evals inflate scores.
Build the eval set first
Before you optimize the prompt, collect 20-100 real examples with known-good outputs. This is your ground truth. Every prompt change gets graded against this set. Without it, you're doing vibes-based development.
Grading strategies
Exact match for structured outputs (parse and compare). Field-by-field match for JSON. Rubric-based grading by a separate Claude call for free-form text. Human grading for genuinely ambiguous cases. Never use the same prompt to generate and grade — the grader shares the generator's assumptions.
Regression tracking
A prompt change that helps one case can break three others. Run the full eval set on every change, not just the case you were trying to fix. Improvements that don't show up on the full set usually weren't real improvements.
Change: added a new instruction to reduce hedging. Before: 78% pass. After: 82% pass. Ship it — the number moved on the held-out set.
Categorical criteria beat vague confidence
A common exam trap: an instruction like 'be conservative' or 'only flag high-confidence issues.' This doesn't reduce false positives — it just shifts the model's tone. What works is CATEGORICAL criteria: precise definitions of what qualifies. 'Flag only when the claimed behavior contradicts observable code behavior' is testable and specific. 'Be careful' is not.
❌ Vague: 'Only flag issues you are highly confident about.' ✅ Categorical: 'Flag an issue only if: - the diff introduces a call to a deprecated API, OR - the diff removes error handling from a public function, OR - the diff mutates a shared cache without a lock. Do NOT flag style, formatting, or naming.'
Anti-patterns in eval design
Building the eval set from the same examples the prompt was tuned on. Using metrics that don't correlate with what users care about. Grading only pass/fail when partial credit matters. Not versioning the eval set.
Takeaways
- Build the eval set before optimizing
- Separate generator from grader
- Run the full set on every change
- Metrics should reflect user-visible quality
Exam traps
Practice scenario
A PostToolUse hook exits with code 2 and writes 'formatter failed' to stderr. What happens?