Stop Breaking Production: Catch Agent Failures Before Users Do
By Mohamed Naser Technical Lead, Lynk
It's 2 AM and Slack is exploding: your AI agent is answering payment questions wrong. You fix the prompt, run a few manual tests, deploy — and by 6 AM three unrelated features have broken. Here is how LLM judges catch that before your users do.
- LLM as a judge
- LLM evaluation
- AI agent testing
- agent regression testing
- semantic evaluation
- judge panel consensus
- multi-turn conversation evaluation
- RAG evaluation
- hallucination detection
- DeepEval
- RAGAS
- LLM CI/CD
- prompt regression
- AI quality assurance
It's 2 AM on a Tuesday, and your Slack is exploding. A customer just reported a critical bug: your AI agent is giving incorrect responses about payment processing. You quickly identify the issue — a faulty assumption in the system prompt. You fix it, run a few manual tests, and deploy with confidence.
By 6 AM, three more bugs appear. Not in payment processing, but in unrelated features: customer support queries, knowledge retrieval, and report generation. Features you didn't touch. Features you thought were working fine.
This is the LLM agent developer's nightmare: every change is a potential cascading failure waiting to happen.
You can't see the ripple effects of your modifications throughout the entire system. Moreover, your users are discovering problems that you were completely unaware of.
The Problem: Manual Testing Doesn't Scale
Your first instinct is reasonable: hire humans to write test scenarios.
You create a test suite of 500 Q&A pairs. Each pair has:
- A question
- The expected answer (from a domain expert)
Every time you change a prompt or modify the agent's behavior, you run all 500 scenarios and mark pass/fail. Simple. Effective. But then reality sets in.
The Two Scalability Killers
1. Speed: Running 500 tests manually takes hours. Testing every PR becomes a bottleneck. You're stuck in reactive mode — users find bugs, you fix them, you deploy. Then more bugs emerge. Proactive testing feels like a luxury you can't afford.
2. Coverage: What about edge cases you haven't thought of yet? What about multi-turn conversations where context switches between finance and sports questions? What about RAG systems where answers need proper source attribution? Adding every scenario manually is an endless treadmill.
The Reactive Trap
You're not discovering problems — users are. And they're discovering them in production.
The ideal would be: evaluate changes before they reach users, automatically, at scale, every single PR.
This is where most teams give up. Testing LLM agents feels impossible.
The Solution: LLM as Judge
What if instead of hiring humans to judge every test, you used an LLM?
Here's the insight: LLMs are surprisingly good at evaluating other LLMs. They can read a question, compare two answers, and judge which one is better — or whether an answer meets a standard.
The pattern is simple:
- You make a code change and create a pull request — this triggers the evaluation
- Your reference dataset (500 question-answer pairs) sits ready as the benchmark
- Your agent code runs and produces answers
- The LLM judge reads both the reference answer and your agent's answer, then decides if they match (or how close they are)
- The judge outputs structured results: Pass/Fail status, a score, and reasoning about any mismatches
- You get a report showing exactly which tests failed and why.
This is not traditional unit testing. It's semantic evaluation — judging whether the agent's behavior matches expectations, even when the wording differs.
Three Approaches to Judging: Pick Your Confidence Level
Now you need to decide: How confident do you want your evaluation to be?
Approach 1: Single Judge
How it works:
- Send the question + agent answer + reference answer to judge LLM
- The judge responds: "Pass" or "Fail"
- Done. Cost: one API call. Time: ~200ms.
The Problem: Bias
Here's where it gets tricky. LLMs have preferences. One model might prefer formal tone, another conversational. One might be strict about exact wording, another lenient.
Imagine:
- Reference answer: "The capital of France is Paris."
- Agent answer: "Paris is the capital of France."
Both are correct. But your judge might say: "I prefer the reference format. The agent answer is inconsistent. Fail."
This is bias. Your valid answer gets marked as failing because the judge has stylistic preferences.
When to use it: quick feedback with low cost in development . Not for critical decisions.
Approach 2: Multiple Judges
How it works:
- Send the same question + answers to 4 different LLM judges simultaneously
- Judge 1 (GPT-4): Score 0.92
- Judge 2 (Claude): Score 0.88
- Judge 3 (Gemini): Score 0.89
- Judge 4 (Local model): Score 0.90
- Average them: 0.897 ✓
Why this works: Each LLM has different biases. If one judge prefers formal tone, another might prefer conversational. Their biases cancel out when you average them.
An outlier score (say, one judge gives 0.65 while others give 0.90) is isolated and doesn't tank your result. The consensus is more robust.
Cost trade-off: 4× the API calls, but you get far more reliable evaluation. Many teams find this is worth it — one false negative from a biased judge could let a bug into production.
Approach 3: Self-Judge (Don't Do This)
Some people suggest: "Why not have the agent evaluate itself?"
Don't. This is maximally biased. The agent is motivated to mark its own answer as correct. You're asking a student to grade their own exam.
What Should You Evaluate?
Not all aspects of agent behavior are equally important. Prioritize what matters to your use case.
1. Single-Turn Q&A (The Baseline)
Simple question → Simple answer. Is the answer correct?
- "What is the Python keyword for looping?" → "for"
This is your foundation. If the agent fails here, nothing else matters.
2. Multi-Turn Conversations (The Real Challenge)
A conversation with context. The user asks multiple questions, sometimes switching topics.
This is where most agents fail. Can your agent remember it was talking about Bitcoin? Or will it get confused and talk about the Chiefs' blockchain technology?
The judge evaluates context coherence: "Did the agent maintain context across topic switches?"
Multi-turn evaluation is harder to build (you need conversation histories, not just Q&A pairs), but it catches real-world failures that single-turn tests miss.
3. RAG Evaluation (Grounding in Reality)
If your agent uses Retrieval-Augmented Generation (RAG), answers should be grounded in sources.
The judge checks:
- Is the answer supported by the retrieved document?
- Are citations valid?
- Did the agent hallucinate?
Example:
- Document: "The Earth orbits the Sun in 365.25 days."
- Agent answer: "The Earth orbits the Sun in 365.25 days, as stated in Document_42."
- Judge: ✓ Answer is grounded.
versus:
- Agent answer: "The Earth orbits Mars, a fact not covered in the documents."
- Judge: ✗ Agent hallucinated.
RAG evaluation requires specialized metrics. We'll cover tools for this below.
What Judges Output (And How to Use It)
Output Type 1: Binary Pass/Fail
Simplest. Useful for regression testing.
- 487 tests passed
- 13 tests failed
- List of failing tests
Use case: "Did this PR break anything?"
Output Type 2: Numerical Score (0–100)
More nuanced. Useful for tracking quality over time.
- Overall quality: 87/100
- Consistency: 0.91
- Relevance: 0.84
- Accuracy: 0.92
Use case: "Is the agent getting better?" Graph these scores over time.
Output Type 3: Pairwise Comparison
Judge two versions and pick the better one.
- Model A answer vs Model B answer: "Model B is better because…"
Use case: A/B testing different prompts. Which one consistently wins?
Output Type 4: Reference-Based Generation
For RAG systems specifically. Judge checks:
- Did the agent cite sources? ✓
- Are those sources valid? ✓
- Is the answer faithful to the source? ✓
Use case: "Can I trust this RAG system to give cited answers?"
| Output Type | Use Case | Confidence |
|---|---|---|
| Pass/Fail | Regression testing | Low (binary) |
| Numerical Score | Quality tracking | Medium |
| Pairwise | A/B testing | Medium-High |
| Reference check | RAG grounding | High |
Tools
You don't need to build the judge logic from scratch. Two frameworks dominate this space.
DeepEval
What it does: Provides pre-built metrics for LLM evaluation.
- Hallucination detection
- Toxicity scoring
- Relevance checking
- Bias detection
- Custom metrics via LLM judge
Best for: General agent evaluation, regression testing, scoring answers.
RAGAS
What it does: Specialized metrics for RAG systems.
- Faithfulness (Is the answer grounded in sources?)
- Answer relevance (Does it answer the question?)
- Context precision (Are retrieved documents actually relevant?)
- Context recall (Did retrieval miss important documents?)
Best for: RAG pipelines where source attribution matters.
Conclusion:
Traditional testing caught bugs after users found them. LLM judges let you catch them before they reach production.
This isn't perfect. LLMs will make mistakes. Your reference dataset might be incomplete. Consensus scoring adds cost. But the alternative — hoping your changes don't break things — is worse.
The pattern is emerging: LLMs evaluating LLMs. It's not just a test framework; it's a new way to think about quality. Every time you deploy an agent, you're not just shipping code. You're shipping a system that can evaluate itself and defend against degradation.
The 2 AM production incident? With LLM judges catching regressions in CI, it becomes a 2 AM fix in code review instead. Not zero-incident, but better. Much better.
This article also appears on Medium, in the How to Profit AI publication, where the comments live.