LLM Evaluation Patterns
Skill4 starsChanged 10 months agoMITView on GitHub
Testing and evaluation patterns for LLM applications using DeepEval and RAGAS. Use for formal evaluation before deployment, after prompt changes, or model updates.
- Reads credentials
- Installs packages
In this repository12 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- Claude Agent SDK PatternsSkill
- delegation-templatesSkill
- deploymentSkill
- frontend-patternsSkill
- Google ADK PatternsSkill
- LLM Observability PatternsSkill
- memory-workflowSkill
- orchestrator-workflowsSkill
- react-native-best-practicesSkill
- skill-creatorSkill
- testing-strategySkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 2 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 149
Rule: Start low, increase as system matures.
- Very specific: line 158
Default: gpt-4 for evaluation (most accurate, most expensive)
- Distinctive: line 181
Run multiple times for stability checks
- Very specific: line 182
Use include_reason=True to understand scoring
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
LLM Evaluation Patterns - Quick Reference
Principle: "Eyeballing outputs is ending" - formal evaluation is required for production AI.
Package: pip install -U deepeval
Modules
- 01-deepeval-setup.md - Installation & Integration
- Installation and environment setup
- pytest integration patterns
- Test organization conventions
- 02-metrics-guide.md - Metric Selection
- Metric selection by use case
- Built-in vs custom metrics (GEval)
- Threshold tuning guidelines
- 03-rag-evaluation.md - RAG Evaluation (DeepEval)
- Retrieval metrics (precision, recall, relevancy)
- Generation metrics (faithfulness, answer relevancy)
- End-to-end RAG pipeline evaluation
- 04-ragas-rag-evaluation.md - RAGAS Framework
- Reference-free RAG evaluation
- RAGAS vs DeepEval decision guide
- Vertex AI integration patterns
- 05-vertex-ai-evaluation.md - Vertex AI Gen AI Evaluation
- GCP-native evaluation service
- Adaptive rubrics (auto-generated criteria)
- Agent trajectory evaluation (tool sequence analysis)
- Pairwise model comparison
When to Evaluate
| Trigger | What to Evaluate |
| Before deployment | Full test suite (all metrics) |
| After prompt changes | Affected metrics only |
| After model updates | Regression tests + key metrics |
| After RAG pipeline changes | Retrieval + faithfulness metrics |
Evaluation vs Unit Testing
| Aspect | Unit Testing | LLM Evaluation |
| Purpose | Code correctness | Output quality |
| Determinism | Deterministic | Non-deterministic |
| Speed | Fast (ms) | Slow (seconds per test) |
| Cost | Free | LLM-as-judge costs |
| Assertions | Exact match | Semantic scoring |
Key Insight: LLM evaluation complements unit tests - both are needed.
Quick Start Pattern
from deepeval import evaluate
from deepeval.metrics import AnswerRelevancyMetric
from deepeval.test_case import LLMTestCase
# 1. Create test case
test_case = LLMTestCase(
input="What is the return policy?",
actual_output="We offer a 30-day full refund.",
retrieval_context=["30 day full refund at no extra cost."]
)
# 2. Define metric with threshold
metric = AnswerRelevancyMetric(threshold=0.7)
# 3. Evaluate
evaluate([test_case], [metric])For pytest integration, see 01-deepeval-setup.md.
Metric Quick Reference
| Use Case | Primary Metrics | Framework |
| General Q&A | AnswerRelevancy, Correctness (GEval) | DeepEval |
| RAG Applications | Faithfulness, ContextualPrecision, ContextualRecall | DeepEval or RAGAS |
| RAG (reference-free) | Faithfulness, ResponseRelevancy, LLMContextPrecision | RAGAS |
| Chatbots | ConversationalGEval, RoleAdherence | DeepEval |
| Factual Tasks | Hallucination, Correctness | DeepEval |
| Safety/Compliance | Bias, Toxicity, PIILeakage | DeepEval |
For detailed metric selection, see 02-metrics-guide.md. For RAGAS vs DeepEval decision, see 04-ragas-rag-evaluation.md.
Project Conventions
Test Organization
tests/
evals/ # LLM evaluations (separate from unit tests)
test_rag_quality.py # RAG pipeline evaluations
test_chatbot_evals.py # Chatbot evaluations
conftest.py # Shared fixtures, datasets
unit/ # Fast unit tests
integration/ # Integration testsNaming Convention
# Pattern: test_[feature]_[metric]_[scenario]
def test_rag_faithfulness_with_context():
...
def test_chatbot_relevancy_simple_query():
...Thresholds
| Metric Type | Development | Staging | Production |
| Relevancy | 0.5 | 0.6 | 0.7 |
| Faithfulness | 0.6 | 0.7 | 0.8 |
| Precision/Recall | 0.5 | 0.6 | 0.7 |
Rule: Start low, increase as system matures.
Common Gotchas
1. LLM-as-Judge Costs
DeepEval uses LLMs to evaluate LLM outputs. Each metric = API call.
- Set
OPENAI_API_KEYor configure custom model - Default:
gpt-4for evaluation (most accurate, most expensive) - Cost-saving: Use
gpt-4o-minifor development
2. Async Handling
DeepEval runs async internally. If using in async code:
# Standalone (not pytest)
import asyncio
asyncio.run(evaluate([test_case], [metric]))3. Test Data Preparation
retrieval_context must be a list of strings, not dict:
# Wrong
retrieval_context={"doc1": "content"}
# Right
retrieval_context=["Document 1 content", "Document 2 content"]4. Non-Deterministic Scores
Same input can produce different scores (LLM variance).
- Run multiple times for stability checks
- Use
include_reason=Trueto understand scoring
Context7 Lookup
For current API syntax:
get-library-docs: /confident-ai/deepeval (topic: "metrics AnswerRelevancy")
get-library-docs: /confident-ai/deepeval (topic: "GEval custom metrics")
get-library-docs: /confident-ai/deepeval (topic: "synthesizer test data")Cross-References
- AI/LLM Testing:
.claude/skills/testing-strategy/08-ai-llm-testing.md(semantic assertions) - pytest patterns:
.claude/skills/testing-strategy/02-unit-testing.md - CI/CD integration:
.claude/skills/testing-strategy/11-ci-cd-integration.md
Last Updated: 2025-12-26
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

