Skip to main content
An evaluation produces a score or label for an output, so you can track quality across runs. Evaluations attach quality signals to runs so that correctness or relevance can be reasoned about consistently instead of judged case by case. Traces tell us what happened during a run, but they don’t tell us whether the output was good; evaluations fill that gap by letting us score outputs in a consistent, repeatable way. In this guide, we’ll set up evaluations in Phoenix so we can measure the quality of model outputs from a real application. We’ll start with data that already exists in Phoenix, define a simple evaluation, and run it so we can see results directly in the UI. The goal is to move from “I have model outputs” to “I can measure quality in a repeatable way.” Since we already have traces, we can take this a step further by scoring them against metrics like correctness, relevance, or custom checks that matter to your use case.

Before We Start

To follow along, you’ll need to have completed Get Started with Tracing so you should have:
  • Financial Analysis and Research Chatbot
  • Trace Data in Phoenix

Follow along with code: This guide has a companion codebase with runnable code examples. Find it here.

Step 1: Make Sure You Have Data in Phoenix

Before we can run evaluations, we need something to evaluate. Evaluations in Phoenix run over existing trace data. If you followed the tracing guide, you should already have:
  • A project in Phoenix
  • Traces containing LLM inputs and outputs
It’s best to have multiple traces so we can see how evaluation results vary from run to run. If needed, run your agent a few times with different inputs to generate more data. We can create a new folder in src/mastra called evals to hold the different scripts we will create during this evaluation guide. The first script we’ll create runs more queries to generate more trace data in our Phoenix project for evaluation. Before running this file, ensure that you have npm run dev in the background. Create a file called add_traces.ts:

Step 2: Define an Evaluation

Now that we have trace data, the next question is how we decide whether an output is actually good. An evaluation makes that decision explicit. Instead of manually inspecting outputs or relying on intuition, we define a rule that Phoenix can apply consistently across many runs. In Phoenix, evaluations can be written in different ways. In this guide, we’ll use an LLM-as-a-judge evaluation as a simple starting point. This works well for questions like correctness or relevance, and lets us get metrics quickly. (If you’d rather use code-based evaluations, you can follow the guide on setting those up.) For LLM-as-a-judge evaluations, that means defining three things:
  • A prompt that describes the judgment criteria
  • An LLM that performs the evaluation
  • The data we want to score
In this step, we’ll define a basic completeness evaluation that checks whether the agent’s output completely answers the input. Phoenix also provides pre-built evaluation templates you can use or adapt for other metrics like relevance or hallucinations. First, create a file called evals.ts in src/mastra/evals to hold our evaluation code. Let’s start by adding our imports and constants at the top of this file. We’ll be using phoenix-evals to create our evaluator and phoenix-client to fetch our traces in code and push our annotations back to the project.

Define the Evaluation Prompt

We’ll start by defining the prompt that tells the evaluator how to judge an answer.
This prompt defines what completeness means for our application.

Create the Evaluator

Now we can combine the prompt and model into an evaluator. We’ll wrap our evaluation logic in a main() function to handle async operations.
At this point, we’ve defined how Phoenix should evaluate completeness, but we haven’t run it yet.

Step 3: Fetch and Filter Trace Data

Before we run our evaluator, we’ll need to pull down our trace data and prepare it to pass into the evaluator. We’ll get all the spans from Phoenix, filter for just the orchestrator agent spans, and extract their input and output values.

Step 4: Run the Evaluator

Now that we have our data and our evaluator, the next step is to run our evaluator on our data.
This produces evaluation results for each span in the dataset.

Step 5: Log Evaluation Results to Phoenix

Finally, we’ll log the evaluation results back to Phoenix so they show up alongside our traces in the UI. This is what makes evaluations useful beyond a single run. Instead of living only in code, results become part of the same view you already use to understand behavior.
Once this completes, head back to Phoenix. You’ll now see evaluation results attached to your trace data in the annotations column, making it easy to understand which runs passed, which failed, and how quality varies across executions.

Tracing Project with Evaluation Annotations

Congratulations! You’ve run your first evaluation in Phoenix.

Learn More About Evals

Now that you have evaluation results in Phoenix, you can start using them to guide iteration. You can group traces with an incorrect label into a dataset, make changes to prompts or logic, and then run experiments on the same inputs to compare how outputs differ. The easiest and fastest way to iterate on your application without writing code is through prompt playground. The Iterate on Your Prompts guide walks through this workflow in more detail. To go deeper on evaluations, the Evaluations Tutorial covers writing more nuanced evaluators, using different scoring strategies, and comparing quality across runs as your application evolves. This was a simple example, but evaluations in Phoenix support much more advanced workflows over time.