Prompt Engineering Evaluation
Prompt engineering evaluation means measuring how well a prompt works on many inputs, not just the one you tried by hand. Without evaluation, a change that fixes one case can quietly break five others.
Build a Test Set
- Collect 20-100 realistic inputs, including hard and edge cases.
- Write the expected output or the criteria a good output must meet.
- Include cases where the right answer is "I don't know" or a refusal.
- Add every real bug you find as a new test case.
Code-Based Checks
Whenever the answer can be checked by code, do that. It is fast, cheap and objective.
tests = [
{"input": "I was charged twice", "expected": "BILLING"},
{"input": "App crashes on login", "expected": "BUG"},
{"input": "Please add CSV export", "expected": "FEATURE"},
]
outputs = ["BILLING", "BUG", "BUG"] # pretend these came from the model
correct = sum(o == t["expected"] for o, t in zip(outputs, tests))
print(f"Accuracy: {correct}/{len(tests)}")Accuracy: 2/3
LLM-as-a-Judge
For open-ended outputs, a second prompt can grade answers against a rubric. Keep the rubric specific and ask for a score plus a short reason.
Grade the answer from 1-5 using this rubric:
5 = correct, complete, cites a source; 3 = mostly correct; 1 = wrong or invented.
Return JSON {"score": n, "reason": "..."}.
Question: ...
Reference answer: ...
Answer to grade: ...Sample response:
{"score": 3, "reason": "Correct deadline but no source cited."}Judges have biases (for example favouring longer answers), so spot-check their grades against human judgement.
Compare Versions
- Run old and new prompt on the same test set.
- Track accuracy, cost (tokens) and latency together.
- Ship only when the new version is better overall, not just on one example.
- Re-run evals when you switch models; behaviour changes between versions.
Frequently asked questions
How many test cases do I need?
Start with 20-50 to catch obvious problems; grow toward hundreds for important production features.
What is LLM-as-a-judge?
Using a language model with a grading rubric to score other model outputs, useful when answers cannot be checked with simple code.
Why do results change when I rerun the same prompt?
Sampling adds randomness. Use low temperature and run each case more than once for a fair comparison.