AI & LLMOps
Continuous Evaluation for Production LLMs: RAGAs, TruLens, and Automated Hallucination Detection
technology.efektifpro.com โ Deploying an LLM application to production without continuous evaluation is flying blind. A minor tweak to a system prompt, a change in document chunking size, or a model version upgrade can quietly degrade retrieval precision or introduce dangerous hallucinations across production user traffic. Continuous LLM Evaluation (LLM-as-a-Judge) transforms evaluation from manual spot-checks into automated CI/CD quality gates.
The RAG Triad: Three Core Metrics of Truth
Modern LLM evaluation frameworks (RAGAs, TruLens) decompose evaluation into three orthogonal, measurable axes known as the RAG Triad:
- Context Relevance: Does the retrieved context actually contain information pertinent to the user’s question? (Tests chunking & vector retrieval).
- Groundedness / Faithfulness: Is every factual claim in the generated answer supported by the retrieved context? (Tests hallucination rate).
- Answer Relevance: Does the generated response directly answer what the user asked without irrelevant digressions? (Tests prompt compliance).
Automating Evaluation Pipelines with RAGAs in Python
# Automated evaluation run evaluating dataset samples
from datasets import Dataset
from ragas import evaluate
from ragas.metrics import (
faithfulness,
answer_relevancy,
context_recall,
context_precision,
)
# Test dataset containing golden questions, retrieved contexts, and model answers
eval_data = {
"question": [
"What is the maximum retention period for payments data under GDPR?",
"How do you configure mTLS between pods in Istio?"
],
"answer": [
"Payments data must be retained for 7 years for tax compliance before mandatory deletion.",
"You configure mTLS by applying a PeerAuthentication resource with mode STRICT."
],
"contexts": [
["Financial records and transaction logs must be preserved for 7 years under corporate tax law."],
["To enforce mutual TLS in Istio, define a PeerAuthentication spec with mTLS mode set to STRICT."]
],
"ground_truth": [
"Under corporate tax law, payment records are preserved for 7 years, after which GDPR mandates deletion.",
"mTLS is enforced across mesh namespaces by setting PeerAuthentication mode to STRICT."
]
}
dataset = Dataset.from_dict(eval_data)
# Execute evaluation using LLM-as-a-judge
results = evaluate(
dataset=dataset,
metrics=[
faithfulness,
answer_relevancy,
context_precision,
context_recall,
],
)
print(results.to_pandas())
Integrating LLM Quality Gates into GitHub Actions CI
Just as unit tests block broken code from merging to main, LLM evaluation test suites should fail pull requests if a prompt change causes faithfulness or context recall scores to drop below established regression thresholds:
# pytest test ensuring regression thresholds are maintained
import pytest
def test_rag_faithfulness_threshold():
score = run_ragas_evaluation()
assert score["faithfulness"] >= 0.90, f"Faithfulness dropped to {score['faithfulness']}"
assert score["answer_relevancy"] >= 0.85, f"Answer relevancy dropped to {score['answer_relevancy']}"
assert score["context_recall"] >= 0.80, f"Context recall dropped to {score['context_recall']}"
Production Guardrails: Real-Time Hallucination Blocking
In addition to pre-deployment testing, high-risk financial and healthcare workflows deploy real-time guardrails (NeMo Guardrails, Guardrails AI). If an LLM response fails an entailment check against the source document, the middleware automatically suppresses the output and falls back to: “The verified documentation does not contain sufficient details to answer this query safely.”
Target KPI Metrics for Enterprise LLM Systems
| Evaluation Metric | Minimum Acceptable | Target Production |
|---|---|---|
| Faithfulness (No Hallucination) | > 88% | > 96% |
| Context Precision | > 80% | > 92% |
| Answer Relevancy | > 82% | > 94% |
| Toxic Output / Jailbreak Rate | 0.0% | 0.0% (strict guardrail) |
