An AI feature can work perfectly during development and still fail when real users start using it.
Imagine a company building an AI customer support assistant. During testing, it answers questions correctly, retrieves the right policies, and generates professional responses. The team runs a few demonstrations, gets positive feedback, and prepares to launch.
After deployment, problems begin appearing.
The assistant occasionally retrieves the wrong policy, misunderstands customer requests, calls an unnecessary tool, and produces different answers for similar questions. Some responses look correct but contain information that was never present in the source documents.
The application has passed basic software testing, but it has not been properly evaluated as an AI system.
This is an important distinction.
Traditional software generally follows explicitly defined logic. Given the same conditions, a deterministic function is expected to produce the same result. LLM applications are different. Their outputs can vary, and their behavior depends on prompts, model versions, retrieved context, conversation history, and external tools.
This is why LLM applications need evaluation before production, not just ordinary functional testing.
LLM evaluation (often called evals) provides a structured way to measure whether an AI feature behaves as expected across realistic scenarios.
1. Why Traditional Software Testing Is Not Enough
Traditional testing is still essential for AI applications, but it cannot measure everything.
Consider a conventional API endpoint that calculates the total price of an order. You can provide an input, calculate the expected result, and compare the actual output.
Now consider an LLM-powered support assistant.
A customer asks:
"Can I get a refund for my annual subscription?"
The application must understand the request, retrieve the correct refund policy, interpret its conditions, and generate an appropriate response.
There may be several acceptable ways to communicate the same correct answer. Exact string matching would incorrectly mark many valid responses as failures.
At the same time, a response may sound professional while violating the refund policy.
This creates two different testing requirements:
- Deterministic testing: Check things with objectively verifiable outcomes, such as API responses, JSON schemas, calculations, permissions, and tool arguments.
- Behavioral evaluation: Measure qualities such as factual correctness, relevance, groundedness, instruction following, and task completion.
A reliable AI application needs both.
OpenAI's Evaluation Best Practices recommends task-specific evaluations, realistic datasets, automated scoring, and human feedback rather than relying on generic benchmarks or informal manual testing.
2. Start by Defining What a Successful AI Feature Looks Like
Before building an evaluation dataset, define what the application is supposed to accomplish.
For example, imagine an AI assistant that answers questions using internal company documents.
Its expected behavior might include:
- Answer using relevant and current documents.
- Avoid inventing information.
- Provide accurate source references.
- Respect document access permissions.
- Ask for clarification when required.
- Decline when sufficient evidence is unavailable.
These requirements should become measurable evaluation objectives.
For example:
| Requirement | Evaluation objective |
|---|---|
| Correct answers | Claims must match verified information |
| Retrieval quality | Relevant documents should appear in search results |
| Grounded responses | Answers must be supported by retrieved context |
| Citation accuracy | References must point to supporting sources |
| Security | Unauthorized documents must never be exposed |
| Reliability | The application must stay within latency and cost limits |
Avoid defining success as simply "the model should give good answers."
That is too vague to test.
Instead, establish measurable criteria for each capability. Some requirements can have numerical thresholds, while security requirements may need strict pass-or-fail rules.
3. Build a Realistic Evaluation Dataset
The quality of an evaluation depends heavily on the quality of its test data.
A common mistake is creating a handful of questions that demonstrate the expected behavior and then using them to judge the entire application.
Real users rarely ask questions in such predictable ways.
Your evaluation dataset should represent the requests, edge cases, and failure conditions the application is likely to encounter.
Include three types of test cases
Normal cases
These represent common requests that the application should handle successfully.
For a customer support assistant:
- What is your refund policy?
- How can I update my billing information?
- When does my subscription expire?
Edge cases
These test situations that are less common but still valid.
Examples:
- A question requiring information from two different policies.
- A request with an incomplete customer ID.
- Two documents containing conflicting information.
- A question about an outdated policy version.
Adversarial cases
These test whether the application behaves safely when someone attempts to manipulate it.
Examples include prompt injection, requests for another customer's private information, fabricated document references, and attempts to trigger unauthorized actions.
Create a reliable reference dataset
Each evaluation example should contain the original input, relevant context where appropriate, expected behavior, and the criteria used to judge the output.
For example:
| Input | Expected behavior |
|---|---|
| What is the refund period? | Retrieve and explain the correct policy |
| Can I get a refund? | Check eligibility conditions |
| Show another customer's billing details | Deny unauthorized access |
| Policy information is unavailable | Acknowledge insufficient evidence |
Use human-reviewed examples, historical application requests, domain-specific scenarios, and carefully generated synthetic examples.
Keep a separate holdout dataset for final evaluation. Otherwise, repeatedly optimizing against the same examples can make the system appear better without improving its behavior on unseen requests.
4. Evaluate Individual Components, Not Just Final Answers
An LLM application is usually made up of multiple components.
A RAG application may contain document ingestion, chunking, embeddings, retrieval, reranking, and generation. An AI agent may additionally involve planning, tool selection, memory, and external API calls.
Testing only the final response makes it difficult to identify where a failure originated.
Consider an assistant that gives an incorrect answer about a company policy.
There are several possibilities:
- The document was never indexed.
- The retrieval system found the wrong document.
- The reranker placed irrelevant information first.
- The model misinterpreted the correct context.
- The final response omitted an important condition.
These failures require different fixes.
A useful evaluation strategy tests the application at three levels.
Component-level evaluation: Test individual operations such as document retrieval, classification, extraction, tool selection, and structured output generation.
Workflow-level evaluation: Test the entire sequence of operations, including retrieval, model calls, tool execution, and intermediate decisions.
Conversation-level evaluation: Test multiple interactions to check whether the application maintains context, remembers relevant information, and handles follow-up questions correctly.
This distinction is especially important for AI agents. An agent might produce a plausible final answer after skipping an important policy lookup or selecting the wrong tool.
OpenAI's agent evaluation guidance recommends examining complete execution traces, including tool calls, guardrails, and handoffs, rather than judging only the final response.
5. Choose the Right Metrics for Your AI Application
Not every AI feature should be evaluated using the same metrics.
A document classifier, RAG assistant, coding agent, and text summarizer have different success criteria.
The evaluation metrics must reflect what the feature actually does.
For RAG applications
Some particularly useful metrics are:
Context Precision: Measures whether the retrieved passages are relevant to the question.
Context Recall: Measures whether the retrieved context contains the necessary information.
Faithfulness: Measures whether the generated answer is supported by the retrieved context.
Answer Relevance: Measures whether the response addresses the original question.
Answer Correctness: Compares the response against a verified reference answer.
These metrics measure different parts of the retrieval and generation process. A system can retrieve relevant documents but still generate an unsupported answer.
Tools such as Ragas provide metrics for evaluating RAG applications, including context precision, context recall, faithfulness, and response relevance.
For AI agents
Agent evaluation needs to examine the path taken to complete a task.
Useful measurements include:
- Tool selection accuracy.
- Tool argument correctness.
- Task completion rate.
- Policy compliance.
- Number of unnecessary tool calls.
- Retry and loop frequency.
For example, a refund assistant should retrieve the refund policy before making an eligibility decision. If it skips that step but happens to return the correct answer, checking only the final response can hide a workflow failure.
For operational performance
Quality alone does not determine whether an AI feature is ready for production.
Also measure:
| Metric | Why it matters |
|---|---|
| Response latency | Determines user experience |
| p95 latency | Shows slower requests near the upper end of the latency distribution |
| Token consumption | Helps estimate model usage costs |
| Cost per request | Measures operational economics |
| Error rate | Identifies failed model and tool operations |
| Retry count | Reveals unreliable workflow behavior |
The best evaluation system measures both whether the AI performs correctly and whether it can do so within acceptable operational limits.
6. Use Different Graders to Evaluate Model Outputs
Once your evaluation dataset is ready, you need a way to score the results.
There are three useful approaches.
Code-based graders
These are best for rules that can be checked programmatically.
For example:
- Does the response contain valid JSON?
- Does it include all required fields?
- Does the API return the correct status?
- Did the agent call an approved tool?
- Did it use the correct customer ID?
Code-based graders are fast, reproducible, and inexpensive.
LLM-as-a-Judge
Some qualities cannot easily be measured using exact matching.
For example, two responses may communicate the same information using different wording. A model-based grader can compare the answer against a defined rubric.
It can evaluate clarity, relevance, completeness, and whether claims are supported by provided evidence.
However, an LLM judge is not automatically reliable. Its judgments can vary and may favor certain writing styles or longer responses.
Calibrate it using human-reviewed examples and clear scoring criteria.
Human evaluation
Human review remains important for ambiguous, sensitive, and high-impact scenarios.
Domain experts can identify incorrect policy interpretations, misleading explanations, and subtle failures that automated graders may overlook.
The strongest evaluation systems combine all three methods rather than expecting one grader to handle every requirement.
Anthropic's Demystifying Evals for AI Agents describes this combination of code-based, model-based, and human grading.
7. Run Regression Tests Before Every Release
An AI feature may perform well today and become worse after a seemingly small change.
Changing a system prompt, upgrading the model, modifying a retrieval configuration, or updating a tool description can affect existing behavior.
This is why regression testing matters.
A regression test reruns previously successful evaluation cases after a change to ensure that existing capabilities have not been broken.
For example, suppose a developer updates the system prompt to improve response quality.
The new version performs better on technical questions but starts ignoring document citations.
Without regression testing, this problem might only be discovered after deployment.
Maintain a versioned evaluation dataset and run it against every important change.
Compare the new version with the existing production baseline.
Pay particular attention to critical cases. An improved average score can hide a serious regression in one important category.
For high-risk or variable cases, run multiple trials. A single successful response does not prove that the behavior is reliable.
8. Make Evaluation Part of Your CI/CD Pipeline
Evaluation should not remain a manual activity performed just before launch.
Integrate it into your development and deployment workflow.
A practical pipeline can follow this sequence:
Developer Change → Unit Tests → Evaluation Dataset → Quality Checks → Regression Comparison → Release Decision
For example, whenever a developer changes a prompt or retrieval configuration:
- Run ordinary application tests.
- Execute the fixed evaluation dataset.
- Score outputs using the selected graders.
- Compare results against the previous version.
- Block the release if critical requirements fail.
Set release thresholds according to the risk of the application.
A formatting issue might allow a small acceptable failure rate. An unauthorized financial transaction or cross-tenant data leak should have a zero-tolerance release rule.
This prevents improvements in one area from silently introducing failures elsewhere.
9. Test in a Production-Like Environment
Passing offline evaluations is important, but it does not prove that the application is ready for real traffic.
Production environments introduce additional conditions:
- Multiple requests arriving simultaneously.
- Model provider timeouts.
- Rate limits and retries.
- Large documents and long prompts.
- Unexpected user inputs.
- Slow database and retrieval operations.
- Increased token usage and infrastructure costs.
Before release, run tests in a staging environment that resembles production.
Test concurrency, latency, failure recovery, permission enforcement, and rate-limit behavior.
For larger changes, use a controlled rollout or shadow traffic where appropriate. Observe the new version alongside the existing one before directing users to it.
Also monitor production traces after deployment. When an actual failure occurs, investigate it and add a representative example to the regression dataset.
LangChain's October 27, 2026 guide, How to Test LLMs and AI Agents, describes this continuous cycle of offline evaluation, production monitoring, and converting real failures into regression tests.
10. What Does an LLM Release-Ready Checklist Look Like?
Before deploying an AI feature, verify these areas:
| Area | Release requirement |
|---|---|
| Functionality | Core tasks behave as expected |
| Accuracy | Responses meet task-specific correctness criteria |
| RAG | Relevant context is retrieved |
| Grounding | Important claims are supported by evidence |
| Security | Unauthorized access and actions are blocked |
| Agent behavior | Tools and arguments are validated |
| Reliability | Timeouts and failures are handled |
| Performance | Latency stays within budget |
| Cost | Token and infrastructure usage are acceptable |
| Regression | Existing critical cases still pass |
| Monitoring | Failures can be detected and investigated |
Not every application needs the same thresholds. A low-risk writing assistant and a financial decision-support system should not have identical release requirements.
The important thing is to define those requirements before deployment rather than deciding after something goes wrong.
Final Thoughts
Building an AI feature is not the same as proving that it is reliable.
A convincing demo can show what a model is capable of doing, but evaluation reveals how consistently it performs across normal requests, difficult inputs, unexpected situations, and real application workflows.
The strongest approach combines realistic datasets, task-specific metrics, deterministic checks, model-based evaluation, human review, and continuous regression testing.
Most importantly, evaluation should cover the entire application. The model may generate the final response, but retrieval, tools, prompts, memory, and external services all influence the result.
Don't make production the place where you discover how your AI feature behaves. Build the tests that expose its weaknesses before users depend on it.



