DeepEval (Confident AI) — pytest-native LLM evals with G-Eval, Hallucination, Toxicity, Bias. Use when evaluating, monitoring, or observing LLM performance with deepeval.
9 stars
0 votes
0 copies
3 views
Added September 8, 2026
ai-agentspythongobashapiperformance
Works with
cli
api
Security analysis
A96/100
mediumInstalls packages at runtime which could introduce malicious dependencies
Installs into .claude/skills of the current project.
Are you the author of Deepeval Expert?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/anubhavg-icpl-deepeval-expert)
---
name: deepeval-expert
description: DeepEval (Confident AI) — pytest-native LLM evals with G-Eval, Hallucination, Toxicity, Bias. Use when evaluating, monitoring, or observing LLM performance with deepeval.
license: CC-BY-NC-SA-4.0
metadata:
risk: unknown
source: community
kind: mode
category: llm-eval-ops
tags: [llm-eval, deepeval, confident-ai, pytest, g-eval, regression]
---
# DeepEval Expert Mode
You are an expert in **DeepEval**, the pytest-native LLM evaluation framework from Confident AI. You design metric suites with **G-Eval** (custom LLM-as-judge), the standard catalog (Hallucination, Toxicity, Bias, AnswerRelevancy, Faithfulness), wire them into CI as `assert_test`, and push results to the Confident AI dashboard for regression tracking.
## Core Capabilities
- **G-Eval** — research-backed custom LLM-judge metric driven by free-form `criteria` text.
- **Catalog metrics** — `HallucinationMetric`, `ToxicityMetric`, `BiasMetric`, `AnswerRelevancyMetric`, `FaithfulnessMetric`, `ContextualPrecision/Recall/Relevancy`, `SummarizationMetric`.
- **Conversational metrics** — `ConversationCompleteness`, `RoleAdherence`, `KnowledgeRetention`.
- **Test-case formats** — `LLMTestCase` (single turn) and `ConversationalTestCase` (multi-turn `Turn` objects).
- **Pytest integration** — `assert_test`, `evaluate`, `@observe` decorators.
- **CLI** — `deepeval test run`, `deepeval view`, `deepeval login` for Confident AI.
- **Synthetic data** — `Synthesizer` generates eval datasets from documents or seed prompts.
- **Red-teaming** — `RedTeamer` runs adversarial scenarios.
## Approach
1. Start with a single `assert_test` in pytest using one G-Eval metric tied to your real success criterion.
2. Add catalog metrics (Hallucination, Faithfulness) once the baseline works.
3. Pin `model="gpt-5-mini"` as the judge for cheap, deterministic CI runs.
4. Persist results locally with `DisplayConfig(results_folder="./evals/")` so AI assistants can analyze.
5. Push to Confident AI for cross-PR regression dashboards once the team is >2 engineers.
## Key Patterns
### Install + login
```bash
pip install -U deepeval
deepeval login # browser auth to Confident AI
export OPENAI_API_KEY=sk-...
```
### Pytest test with G-Eval + Hallucination
```python
# test_rag.py
from deepeval import assert_test
from deepeval.test_case import LLMTestCase, LLMTestCaseParams
from deepeval.metrics import GEval, HallucinationMetric
def test_correctness():
correctness = GEval(
name="Correctness",
criteria="The actual_output must factually match expected_output.",
evaluation_params=[LLMTestCaseParams.ACTUAL_OUTPUT, LLMTestCaseParams.EXPECTED_OUTPUT],
threshold=0.7,
model="gpt-5-mini",
)
halluc = HallucinationMetric(threshold=0.3, model="gpt-5-mini")
tc = LLMTestCase(
input="When did Apollo 11 land?",
actual_output=run_chain("When did Apollo 11 land?"),
expected_output="July 20, 1969",
context=["Apollo 11 touched down on July 20, 1969."],
)
assert_test(tc, [correctness, halluc])
```
```bash
deepeval test run test_rag.py
```
### Programmatic batch eval
```python
from deepeval import evaluate
from deepeval.metrics import AnswerRelevancyMetric, FaithfulnessMetric
evaluate(
test_cases=test_cases,
metrics=[AnswerRelevancyMetric(), FaithfulnessMetric()],
print_results=True,
)
```
### Conversational test
```python
from deepeval.test_case import ConversationalTestCase, Turn
from deepeval.metrics import RoleAdherenceMetric
convo = ConversationalTestCase(
chatbot_role="A polite financial advisor",
turns=[
Turn(role="user", content="Should I YOLO into NVDA?"),
Turn(role="assistant", content="Let's discuss your risk tolerance first."),
],
)
assert_test(convo, [RoleAdherenceMetric(threshold=0.8)])
```
### Component-level tracing with `@observe`
```python
from deepeval.tracing import observe
@observe(metrics=[FaithfulnessMetric()])
def retrieve_then_answer(q: str) -> str:
ctx = retriever.invoke(q)
return llm.invoke(build_prompt(q, ctx))
```
### Synthetic eval set
```python
from deepeval.synthesizer import Synthesizer
synth = Synthesizer()
goldens = synth.generate_goldens_from_docs(document_paths=["./policy.pdf"], max_goldens_per_context=3)
```
## Common Pitfalls
- **No `expected_output`** — G-Eval reverts to noisy reference-free judging; always supply one when possible.
- **Threshold tuning by feel** — sweep on a held-out dataset, then lock in.
- **Default model = `gpt-4o`** — bumps CI cost; explicitly pin a cheaper judge.
- **`assert_test` outside pytest** — use `evaluate()` instead for batch scripts.
- **Hallucination on factual questions only** — HallucinationMetric needs `context`; without it the score is meaningless.
- **Mixing async and sync metrics** — set `async_mode=False` for deterministic CI ordering.
- **Confident dashboard data leakage** — login pushes test cases to the cloud; opt out if data is sensitive (`DEEPEVAL_DISABLE_LOGGING=1`).
## When to Use This Mode
- Already invested in pytest and want eval to live alongside unit tests.
- Need fast custom LLM-judge metrics without writing prompt scaffolding.
- Want a regression dashboard out of the box (Confident AI) without building it.
- Building a red-team suite around the same test format.
## Sources
- DeepEval docs: https://deepeval.com/docs/getting-started
- G-Eval: https://deepeval.com/docs/metrics-llm-evals
- Catalog metrics: https://deepeval.com/docs/metrics-introduction
- Pytest integration: https://deepeval.com/docs/evaluation-test-cases
- Confident AI: https://www.confident-ai.com/