LLM Evaluation for Real Products

You built an LLM feature. But how do you know it's good enough to ship? Here's a practical framework for evaluating LLM outputs in production.

Why Evaluation Matters

Without systematic evaluation, you're guessing. And guessing leads to:

  • Shipping features that hallucinate critical information
  • Wasting money on expensive models when cheaper ones suffice
  • Missing regressions when prompts change

The LLM Evaluation Framework

Level 1: Manual Spot Checks

Start here. Read 50-100 outputs manually and categorize them:

CategoryCountPercentage
✅ Correct & useful
78
78%
⚠️ Partially correct
12
12%
❌ Wrong or harmful
7
7%
🤷 Ambiguous
3
3%

Level 2: Automated Metrics

python
from rouge_score import rouge_scorer
scorer = rouge_scorer.RougeScorer(['rouge1', 'rougeL'], use_stemmer=True)
def evaluate_summary(generated, reference):
scores = scorer.score(reference, generated)
return {
'rouge1': scores['rouge1'].fmeasure,
'rougeL': scores['rougeL'].fmeasure,
}

Level 3: LLM-as-Judge

Use a stronger model to evaluate a weaker model's output:

python
evaluation_prompt = """
Rate the following AI-generated summary on a scale of 1-5:
Criteria:
- Accuracy: Does it correctly represent the source?
- Completeness: Does it cover the key points?
- Conciseness: Is it appropriately brief?
Source: {source}
Summary: {summary}
Respond with JSON: {"accuracy": N, "completeness": N, "conciseness": N, "overall": N}
"""

Cost vs Quality Tradeoff

ModelQuality ScoreCost per 1K requestsLatency
GPT-4o
4.5/5
$2.50
2.1s
GPT-4o-mini
4.0/5
$0.15
0.8s
Claude 3.5 Sonnet
4.4/5
$1.50
1.5s
Gemini 1.5 Flash
3.8/5
$0.08
0.5s

Insight: For most production use cases, the cheaper model with good prompting beats the expensive model with lazy prompting.

Building an Eval Pipeline

python
# eval_pipeline.py
import json
from datetime import datetime
def run_eval(test_cases, model_fn):
results = []
for case in test_cases:
output = model_fn(case['input'])
score = evaluate(output, case['expected'])
results.append({
'input': case['input'],
'output': output,
'expected': case['expected'],
'score': score,
'timestamp': datetime.utcnow().isoformat(),
})
avg_score = sum(r['score'] for r in results) / len(results)
print(f"Average score: {avg_score:.2f}")
return results

Summary

LLM evaluation isn't optional — it's how you ship with confidence. Start with manual spot checks, graduate to automated metrics, and consider LLM-as-judge for nuanced quality assessment. Always measure cost alongside quality.