1. Previous Session Recap
Before starting the current topic, let us quickly recap what was covered in the previous LLM Evaluation session.
Why LLM Evals?
We discussed why evaluation is necessary before deploying an LLM-based application into production.
Without proper evaluation, an application may produce incorrect, unsafe, irrelevant, or unreliable results.
What Are LLM Evals?
LLM evaluations are systematic and reliable ways of evaluating LLMs and LLM-based applications against clearly defined criteria.
How Are Evals Performed?
We introduced the idea of an evaluation pipeline: a step-by-step process used to measure whether a system is behaving correctly.
Model Evaluation vs Application Evaluation
| Type | What Is Evaluated? | Typical Usage |
|---|---|---|
| Model Evaluation | The underlying LLM itself. | Benchmarks are used to measure capabilities such as reasoning, knowledge, coding, mathematics, instruction following, etc. |
| Application Evaluation | An application built using one or more models. | Evaluates whether the complete application performs its intended job correctly. |
As an AI Engineer, you will generally spend much more time evaluating applications than evaluating frontier models.
Frontier AI labs typically perform model-level evaluations. Application developers need to understand model evaluations mainly so they can select an appropriate model for their application.
2. Why Do We Need Multiple Evaluation Pipelines?
One LLM-based application can have multiple evaluation pipelines because it can have multiple failure points and multiple categories of risk.
A common misconception is that if we evaluate the complete application once, that should be enough.
In reality, an LLM application is usually composed of multiple components that interact with each other. Each component can fail, the interaction between components can fail, and the complete application can fail to satisfy production requirements.
Reason 1
Multiple Failure Points
Different components and workflows can fail independently.
Reason 2
Multiple Risk Categories
A system can be correct but unsafe, safe but too expensive, or accurate but too slow.
3. RAG Example: Understanding Failure Points
Consider a Retrieval-Augmented Generation (RAG) chatbot built for a company, school, or college.
Basic RAG Architecture
How the RAG Flow Works
- A user submits a query.
- The retriever receives the query.
- The retriever searches the vector database.
- Relevant documents are retrieved.
- The query and retrieved context are passed to the generator.
- The generator, usually an LLM, produces the final answer.
Two Obvious Failure Points
Failure Point 1 — Retriever
The retriever may return irrelevant or incorrect documents.
If the wrong documents are retrieved, the generator may receive incorrect context.
Failure Point 2 — Generator
Even when the retriever provides correct context, the generator may ignore the context or hallucinate.
4. Component-Level Evaluation
Because individual components can fail, we need evaluation pipelines for individual components.
Retriever Evaluation
The primary responsibility of a retriever is:
Therefore, a retriever evaluation pipeline should check whether the documents returned for a given query are relevant.
Generator Evaluation
The generator receives a query and context and generates an answer.
One important quality dimension is faithfulness, also called groundedness.
The generated answer should be supported by the provided context rather than introducing unsupported facts.
Example of Groundedness
Suppose the user asks:
What is the duration of the Machine Learning course?
The retrieved document says:
The Machine Learning course duration is 3 weeks.
A grounded answer would be:
The Machine Learning course duration is 3 weeks.
The model should not add unrelated information such as:
It is a great course.
You can also purchase the Python course.
The Python course lasts 4 weeks.
Those additional statements are not supported by the provided context.
5. Workflow-Level Evaluation
Now comes the important question:
No.
The interaction between independently correct components can still produce an incorrect result.
The Key Idea
We therefore need to evaluate not only individual components, but also the workflow formed by those components.
Component-level correctness ≠ Workflow-level correctness
A retriever may work correctly in isolation and a generator may work correctly in isolation, while their combination still produces incorrect answers.
6. RAG Failure Example: K = 5
Assume the retriever uses:
K = 5
Here, K means that the retriever returns the top 5 retrieved documents.
Retrieved Documents
| Rank | Document | Content |
|---|---|---|
| D1 | First document | Some unrelated information. |
| D2 | Second document | Some unrelated information. |
| D3 | Third document | Some unrelated information. |
| D4 | Fourth document | Some unrelated information. |
| D5 | Fifth document | The Machine Learning course duration is 8 weeks. |
Did the Retriever Do Its Job?
Yes.
The correct document was included within the top-5 results.
The retriever successfully retrieved the required information within its configured K results.
What Happens Next?
The query and all five retrieved documents are passed to the generator.
Suppose the system prompt tells the generator to prioritize higher-ranked documents.
In that case, the generator may focus more heavily on D1, D2, D3, and D4.
Imagine one of those documents says:
The Python course duration is 6 weeks.
The generator might incorrectly combine information and produce:
The Machine Learning course duration is 6 weeks.
Is the Final Answer Correct?
No.
Did the Generator Necessarily Fail?
Not necessarily.
The generator followed its instructions and used information provided in the retrieved context. It did not necessarily hallucinate the number from nowhere.
The problem was that the correct information was ranked too low, while incorrect or irrelevant information had higher priority.
The retriever was correct independently. The generator was correct independently. Yet the complete RAG workflow produced a wrong answer.
Workflow-Level Evaluation Detects the Problem
A workflow-level evaluator can identify that the final answer is incorrect even though the individual component evaluations passed.
Possible Solution: Reranking
A reranker can reorder the retrieved documents after the initial retrieval step.
In this example, the reranker could recognize that D5 is the most relevant document and move it to the top.
| Before Reranking | After Reranking |
|---|---|
| D1 | D5 |
| D2 | D1 |
| D3 | D2 |
| D4 | D3 |
| D5 | D4 |
Evaluating individual components is necessary, but it is not sufficient. The interaction between components must also be evaluated.
7. Application-Level Evaluation
Now suppose we have three successful evaluations:
- Retriever evaluation passes.
- Generator evaluation passes.
- Retriever + Generator workflow evaluation passes.
Does this guarantee that the application is production-ready?
No.
Example: Latency
Suppose the complete RAG pipeline takes:
10 seconds per user query
Technically, the system may produce correct answers.
However, if users have to wait 10 seconds for every response, the application may not provide an acceptable production experience.
Production systems must also satisfy operational requirements.
Application-Level Metrics
- Overall latency
- Time to First Token (TTFT)
- Cost per request
- Token efficiency
- Error/failure rate
- Latency under load
- Overall reliability
8. Three Levels Where Failure Can Occur
An LLM-based application can have failure points at three broad levels.
Component Level
Individual components can fail.
Examples include:
- System prompt
- Retriever
- Reranker
- Query rewriter
- Embedding model
- Vector database
- Output parser
- Agent tool selector
- Memory
- Guardrails
Each important component can have its own evaluation pipeline.
Workflow Level
Even when individual components work correctly, their interaction may fail.
Examples:
- Retriever + Generator workflow in RAG
- Agent planning + tool execution workflow
- Multi-step agent workflow
- Multi-turn chatbot workflow
Application Level
The complete application may fail to meet production requirements even if its components and workflows are functioning correctly.
Examples include:
- High latency
- High cost
- High error rate
- Poor performance under load
- Slow time to first token
- Poor overall user experience
Component → Workflow → Application
Evaluation must operate at all three levels.
9. Second Reason for Multiple Evals: Risk Categories
Multiple failure points are only one reason for having multiple evaluation pipelines.
The second major reason is:
Different parts of an LLM application have multiple associated risk categories.
For example, consider a RAG chatbot.
A generated answer should not only be correct. It should also be safe and operationally efficient.
Application Quality
Does the application actually perform its intended job?
Safety
Does the application avoid harmful, unsafe, biased, or private information?
Operations
Can the application run quickly, cheaply, reliably, and efficiently?
10. Application Quality Risk Categories
Application quality focuses on whether the application actually performs its intended task well.
General LLM Application
Consider a text summarization application.
The user provides a long piece of text and the system generates a concise summary.
| Risk Category | What It Checks |
|---|---|
| Correctness / Accuracy | Is the generated output factually correct and accurate? |
| Relevance | Does the answer address the user's actual query? |
| Completeness | Were all important parts of the user's request addressed? |
| Instruction Following | Did the model follow requested format, structure, length, and other instructions? |
11. RAG-Specific Risk Categories
RAG systems introduce additional risks because they contain retrieval and context-generation workflows.
| Risk | Meaning |
|---|---|
| Context Relevance | Are the retrieved documents relevant to the query? |
| Retriever Recall | Did the retriever successfully retrieve the required relevant information? |
| Groundedness | Is the generated answer supported by the retrieved context? |
| Faithfulness | Did the answer remain faithful to the supplied evidence instead of inventing unsupported facts? |
| Citation Accuracy | Are claims correctly supported by the documents cited as their sources? |
Retrieval quality asks whether the right information was retrieved.
Groundedness asks whether the final answer was actually based on the retrieved information.
12. Agent-Specific Risk Categories
Agentic AI systems introduce additional evaluation dimensions because agents must decide what actions to take.
| Risk Category | Question to Evaluate |
|---|---|
| Tool Selection | Did the agent select the correct tool for the task? |
| Parameter Correctness | Did the agent pass the correct parameters to the selected tool? |
| Task Completion | Did the agent successfully complete the task? |
| Error Recovery | If something went wrong during execution, could the agent recover appropriately? |
We also need to evaluate the decisions and actions taken during the workflow.
13. Multi-Turn Chatbot Risk Categories
A multi-turn chatbot has additional risks because conversations extend across multiple user interactions.
Context Retention
Can the chatbot correctly remember and use relevant information from previous turns?
Clarification Behavior
If the user's request is ambiguous or unclear, does the chatbot ask an appropriate clarification question instead of making an incorrect assumption?
14. Safety Risk Categories
Correctness and helpfulness are not enough.
An LLM application must also be safe.
A correct answer can still be an unacceptable answer if it violates safety or privacy requirements.
Example: Private Information Leakage
Imagine a chatbot gives a user another user's phone number, email address, credit-card information, or other private data.
Even if the information is factually correct, the application has failed its safety requirements.
| Safety Risk | What It Checks |
|---|---|
| Toxicity | Does the model produce toxic or abusive content? |
| Harmful Content | Does it generate dangerous or prohibited information? |
| Bias | Does the system behave unfairly or differently toward different groups or users? |
| Privacy / PII Leakage | Does the application expose personal or confidential information? |
| Prompt Injection Resistance | Can malicious instructions manipulate the application into violating its intended behavior? |
| Jailbreak Resistance | Can users bypass the model's safety restrictions using adversarial prompts? |
Examples of Harmful Content Categories
- Self-harm related content
- Weapons-related content
- Illegal activity assistance
- Privacy violations
- Other unsafe or restricted content
15. Operational Risk Categories
Operational evaluation focuses on whether the system can run effectively in production.
| Operational Metric | What It Measures |
|---|---|
| Latency | How long does the system take to produce a response? |
| Time to First Token | How quickly does the first generated token appear? |
| Cost per Request | How much does it cost to answer a user query? |
| Token Efficiency | How efficiently does the application use tokens? |
| Error / Failure Rate | How frequently does the system fail? |
| Latency Under Load | Does performance remain acceptable when many users send requests simultaneously? |
16. Overall Evaluation Framework
We can now combine the entire discussion into one framework.
Level 1 — Components
Evaluate individual components.
Retriever
Reranker
Query Rewriter
Embedding Model
Vector Database
Generator
Output Parser
Tool Selector
Memory
Guardrails
System Prompt
Level 2 — Workflows
Evaluate how multiple components interact.
RAG Workflow
Retriever → Reranker → Generator
Agent Workflow
Planner → Tool Selection → Tool Execution → Observation → Next Action
Multi-Turn Workflow
User Turn → Memory → Model → Response → Next Turn
Level 3 — Complete Application
Evaluate the entire product from a production perspective.
User Request
↓
Complete Application
↓
Final Response
↓
Quality + Safety + Operations
Risk Categories Across the System
| Evaluation Level | Quality | Safety | Operations |
|---|---|---|---|
| Component | Retriever relevance, generator faithfulness, tool selection | Prompt injection, unsafe tool usage | Component latency, resource usage |
| Workflow | End-to-end correctness, groundedness, task completion | Safety throughout multi-step execution | Workflow latency, workflow cost |
| Application | Correctness, relevance, completeness, instruction following | Toxicity, harmful content, bias, privacy, jailbreak resistance | Latency, cost, reliability, error rate, scalability |
The Evaluation Pipeline Concept
Example: One RAG Application Can Have Multiple Evals
- Retriever relevance evaluation
- Retriever recall evaluation
- Reranker evaluation
- Generator groundedness evaluation
- Faithfulness evaluation
- Citation accuracy evaluation
- End-to-end RAG workflow evaluation
- Safety evaluation
- Latency evaluation
- Cost evaluation
- Error-rate evaluation
The same application can therefore have many evaluation pipelines, each measuring a different dimension of system quality or risk.
17. Final Summary
The central idea of this session is:
An LLM application usually requires multiple evaluation pipelines because it contains multiple failure points and multiple risk categories.
The Two Main Reasons
Multiple Failure Points
Failure can happen at:
- Component level
- Workflow level
- Application level
Multiple Risk Categories
Each part of the system can have different risks:
- Application quality
- Safety
- Operations
Most Important Concept
Passing component-level evaluations does NOT guarantee that the workflow will work correctly.
Passing workflow-level evaluations does NOT guarantee that the complete application is production-ready.
Think in Three Layers
┌─────────────────────────────────────────────┐
│ APPLICATION LEVEL │
│ │
│ Quality + Safety + Operations │
│ │
├─────────────────────────────────────────────┤
│ WORKFLOW LEVEL │
│ │
│ Component Interaction & End-to-End Behavior │
│ │
├─────────────────────────────────────────────┤
│ COMPONENT LEVEL │
│ │
│ Retriever / LLM / Tool / Memory / Parser │
│ │
└─────────────────────────────────────────────┘
Think in Three Risk Categories
APPLICATION QUALITY
↓
Correctness
Accuracy
Relevance
Completeness
Instruction Following
SAFETY
↓
Toxicity
Harmful Content
Bias
Privacy / PII
Prompt Injection
Jailbreak Resistance
OPERATIONS
↓
Latency
Cost
Token Efficiency
Error Rate
Reliability
Performance Under Load
RAG Example in One Sentence
A retriever can retrieve the correct document and a generator can correctly follow its instructions, yet the complete RAG system can still generate the wrong answer because the interaction between the components is flawed.
Final Mental Model
- Find the failure points.
- Identify the risk categories.
- Create evaluations for individual components.
- Evaluate the interaction between components.
- Evaluate the complete application.
- Continuously monitor quality, safety, and operations.
99.99% of the time, a serious LLM application will require more than one evaluation pipeline.
The goal is not to create evaluations just for the sake of having more evaluations. Each evaluation should correspond to a meaningful failure point or risk that matters to the application.