LLM Evaluation & Testing
Evaluate LLM outputs systematically with reference-based metrics, LLM-as-judge, RAGAS for RAG evaluation, and regression test suites.
LLM evaluation is the practice of measuring the quality of AI-generated outputs. Without systematic evaluation, you can't know if prompt changes improved or degraded your system, or whether a new model is better than the current one.
Build an eval suite before deploying, not after. Use LLM-as-judge for nuanced quality assessment. Track metrics across versions. Treat eval as a product function: maintain a golden dataset, run evals on every significant change, and set quality gates.
Workflow
- Define evaluation criteria and a golden datasetVague quality standards produce meaningless evals; a golden dataset enables regression detection.
- Implement LLM-as-judge evaluationHuman evaluation is slow; LLM-as-judge scales and correlates well with human ratings when properly calibrated.
- Evaluate RAG pipelines with RAGASRAG introduces retrieval quality as an additional failure mode separate from generation quality.
- Build automated regression test suitesManual spot-checking can't catch regressions across hundreds of test cases every time you change a prompt.
- Use reference-free metrics for scaleReference-based metrics (BLEU, ROUGE) require golden answers; reference-free metrics scale to arbitrary outputs.
Output Format
Golden dataset with 50+ examples, LLM-as-judge pipeline with rubric, RAGAS scores for RAG components, CI eval gate, trend dashboard.
Examples
LLM judge prompt: `"You are an expert evaluator. Rate the response for ACCURACY (1-5). 1=Incorrect, 3=Partially correct, 5=Fully accurate. Input: {input}. Response: {response}. Expected: {expected}. Output valid JSON only: {"score": N, "reasoning": "..."}"` RAGAS eval: `from ragas import evaluate; from ragas.metrics import faithfulness, answer_relevancy; results = evaluate(dataset, metrics=[faithfulness, answer_relevancy]); print(results.to_pandas())`CI gate: `score = run_eval(golden_dataset); assert score["accuracy"] >= 0.85, f"Accuracy {score['accuracy']} below threshold 0.85"`Edge Cases & Gotchas
- LLM judge bias: judges favor longer, verbose responses regardless of accuracy; calibrate with known-good/bad examples and check correlation with human ratings
- Dataset contamination: if golden examples appeared in training data, the model may memorize them; validate on held-out sets and regularly add new examples
- Stochastic outputs: temperature > 0 produces variable outputs; run each input 3-5 times and average scores, or use temperature=0 for deterministic evals
When to Break These Rules
- For pure classification tasks (sentiment, intent detection) with clear labels, traditional ML metrics (F1, AUC-ROC) are more reliable than LLM-as-judge.
Reference Files
RAGAS: https://docs.ragas.io/Braintrust: https://www.braintrust.dev/LangSmith evals: https://docs.smith.langchain.com/evaluationOpenAI evals: https://github.com/openai/evals