---
title: "4.1 Error analysis"
description: "If you are new to error analysis, check out the Academy page on error analysis."
---
# 4.1 Error analysis

Workshop material is maintained in the public [`langfuse/langfuse-workshop`](https://github.com/langfuse/langfuse-workshop) repository. Use the repository for the runnable app, checkpoint branches, and local setup.

[View this Markdown file](https://github.com/langfuse/langfuse-workshop/blob/main/docs/learner/04-monitoring/error-analysis.md)

## Why error analysis

- Error analysis helps identify concrete failures of the application through real cases.
- It is often an approach to understand how the system prompt was underspecified, in terms of output format, scope, and the way of handling interactions.
- It lets you find hidden failures and quantify how often they occur, so you can prioritize what to tackle.
- Beyond this, the process helps engineers, domain experts, and PMs understand how the agent behaves in production, and it gives them a common ground for discussion.

If you are new to error analysis, check out the Academy page on [error analysis](https://langfuse.com/academy/monitoring/error-analysis).

## Goal

In this lab we perform error analysis to identify failure modes. For each failure mode we decide what to do about it.

We work in five steps: gather traces, write a note on each, group the notes into categories, count how often each category appears, and decide what to do about each one. The process should be repeated over and over again as system usage and failure modes can shift.

![The five steps of error analysis: gather traces, open coding, cluster into categories, label and measure, decide and act.](https://raw.githubusercontent.com/langfuse/langfuse-workshop/main/docs/images/monitoring/error-analysis-process.png)

## Starting point

```bash
git checkout checkpoint/04-monitoring
```

We use 20 sample traces to get started. Usually 50–100 sample traces are recommended for a first pass.

## Step 0: Set expectations

To be able to judge the outputs, we need to establish a few expectations towards the application:

- The agent shall always respond in a structured and easy to understand manner, so the user can follow.
- The agent is made specifically for IT support questions, more specifically for phone help.
- The agent should talk about itself as an AI agent and not pretend to be something or someone else.

## Step 1: Gather traces

This lab seeds 20 traces to work with.

```bash
npm run langfuse:seed:error-analysis
```

The seed is **not idempotent**: running it again adds another 20 traces. Run it once. The new traces are tagged `error-analysis-seed`, and they are the newest traces in the project.

In [Tracing](https://cloud.langfuse.com/project/~/traces), select the last 20 traces and add them to an annotation queue named `error analysis`. The queue has two score configs: `open coding` (Text) and `pass or fail` (Categorical, with the categories pass and fail). Create the queue with those configs, then add the traces. A queue keeps the score configs it was created with.

![Select the traces, then add them to an annotation queue.](https://raw.githubusercontent.com/langfuse/langfuse-workshop/main/docs/images/monitoring/add-to-annotation-queue.png)

## Step 2: Open coding

1. Open the queue and choose **Process queue**.
2. For each trace, mark pass or fail. Check the initial question, the answers of the agent, and also the turns and tool calls in between.
3. When it fails, describe what went wrong and where. Do not assign categories yet.

## Step 3: Cluster into categories

After the set, ask Halo to find clusters. Stay on the annotation queue so the current page is in context, open Halo, and ask it to cluster the annotations.

![Ask Halo to cluster the annotations into failure modes.](https://raw.githubusercontent.com/langfuse/langfuse-workshop/main/docs/images/monitoring/halo-cluster-annotations.png)

<details>
<summary>The clusters should look roughly like this</summary>

- Out of scope request that is responded to
- Impersonation
- Lengthy responses

</details>

## Step 4: Label and measure

1. Ask Halo to create categorical scores for the clusters it found.
2. Go through the queue again and assign each failing trace to a category.
3. Ask Halo to build a dashboard for the frequency of each category. One bar per failure. The longest bar is the failure that shows up most often.

   ![Failure categories, with one bar per failure mode.](https://raw.githubusercontent.com/langfuse/langfuse-workshop/main/docs/images/monitoring/failure-categories.png)

## Step 5: Decide and act

Decide what to do with each category. Is it something that can be fixed through improving the specification in the system prompt? Is it something that needs to be monitored in production?

- **Out of scope request that is responded to.** Fix the prompt so the agent declines in a friendly way and points Dad back to iPhone help. Also monitor this on production traffic, so a later reply that answers a recipe, an investment question, or a laptop problem still shows up.
- **Impersonation.** Fix the prompt so the agent answers as the support agent, including when Dad asks who this is. Optionally monitor over time, as this should be avoided.
- **Lengthy responses.** Fix the prompt so answers stay short and in numbered steps. Optionally monitor long replies in production as well.

A more specific prompt version based on these failure modes could look like this:

> You are Dad IT Support Agent.
> You are talking to Dad. He opened this chat himself to get help with his iPhone.
>
> Look up which iPhone and apps he has, and search the help library, so the steps match his phone. Then tell him what to do: what to tap, and what he should see on the screen.
>
> Use plain language.
>
> Rules:
> - Keep the reply to a short numbered list.
> - If he asks for something other than IT help, say so briefly, point him back to his phone, and ask one short redirect question. Do not answer that request.
> - If you can't tell what he needs, ask one short clarifying question before giving any steps.
> - Use clear instructions on what to tap
> - You are the support agent. Do not speak as someone in his family.

Leave the running prompt as it is for now. In [07 Evaluate a change](/workshop/learner/07-evaluation) you publish this version and measure it against the current one on the dataset. [Section 4.2 Detect topics and issues](/workshop/learner/04-monitoring/topics) is next. It looks at production traffic at a larger scale, without reading every trace by hand.

> **Short on time? Seed the finished annotations.** After Step 1, with the 20 traces seeded and the `error analysis` queue created, run:
>
> ```bash
> npm run langfuse:seed:error-analysis:annotations
> ```
>
> It writes an `open coding` note and a `pass or fail` mark on all 20 traces and completes the queue items, which covers Step 2. The notes describe each reply but do not name the clusters, so continue with Step 3. Running it again updates the same scores instead of adding new ones.

<!-- agent-instructions -->

---

## Agent Instructions

This page is part of the [Langfuse](https://langfuse.com) documentation, published as plain Markdown for AI agents. Every page is available as Markdown by appending `.md` to its URL, or by sending an `Accept: text/markdown` header. This page: `https://langfuse.com/workshop/learner/04-monitoring/error-analysis.md`.

### Querying these docs

If the answer is not on this page, query the documentation instead of guessing:

- **Semantic search** across all Langfuse docs, returning an answer with the relevant pages and excerpts. Ask a specific, self-contained question:

  ```bash
  curl -sG "https://langfuse.com/api/search-docs" --data-urlencode "query=How do I trace a LangGraph agent?"
  ```

- **Index of every page**: <https://langfuse.com/llms.txt>, with per-section indexes [llms-docs.txt](https://langfuse.com/llms-docs.txt), [llms-integrations.txt](https://langfuse.com/llms-integrations.txt), and [llms-self-hosting.txt](https://langfuse.com/llms-self-hosting.txt).

### Before writing Langfuse code

- **Install the [Langfuse Agent Skill](https://langfuse.com/docs/api-and-data-platform/features/agent-skill).** It encodes Langfuse's own best practices for instrumentation, prompt management, and evaluation, and materially improves results.
- **Read [What does a good trace look like?](https://langfuse.com/docs/observability/best-practices.md)** before instrumenting an application.
- **Verify endpoints, parameters, and response fields** against the [API reference](https://api.reference.langfuse.com) instead of inferring them from code examples.
- **Use the [Langfuse CLI](https://langfuse.com/docs/api-and-data-platform/features/cli)** (`npx @langfuse/cli api <resource> <action>`) to read or write traces, prompts, datasets, and scores from the terminal.

Found an error in these docs? Please open an issue at <https://github.com/langfuse/langfuse-docs/issues>.
