Skip to main content
You can see your traces and understand agent behavior. But how do you measure what matters to your specific app? The built-in metrics (latency, token count, error rate) are a start, but they won’t tell you your cost per query, what percentage of responses are hallucinated, or how many distinct sessions you’re handling. Custom metrics let you define exactly what you need to track. Each one is a single query in Arize Query Language (AQL) — a SQL-like language — that returns one number, which then shows up in your dashboards and monitors.
Let Alyx write the AQL for you. Press Cmd+L (macOS) or Ctrl+L (Windows/Linux) to open Alyx and try: “Create a metric for the percentage of traces over 50s latency”

How to set up custom metrics

Open your project, click the ... menu in the top right, and select Custom Metrics. From there, you have three ways to create one:
Click New Custom Metric. On the right side of the page, Alyx can either recommend a metric or translate one you describe into AQL.Ask for a recommendation if you’re not sure what to track:
  • “What metrics should I set up for this project?”
  • “Suggest a quality metric based on the evals I’m running”
Describe a metric in plain English if you already know what you want:
  • “Count responses flagged as hallucinated”
  • “Percentage of retriever spans where Relevance is ‘relevant’”
  • “Total token cost divided by number of distinct sessions”
  • “A weighted score: 25% QA correctness plus 75% relevance”
Alyx drops the AQL into the SQL Query box. Edit, name, save.
Creating a custom metric with Alyx — natural language prompt on the right generates AQL in the SQL Query box

Common patterns

Wondering what to put in the SQL Query box? Most custom metrics fall into one of five shapes. Each section below has a template you can adapt plus a concrete example. Every example starts with a -- description comment, which is the format Alyx generates and a useful habit for readability.

1. Count of an eval label

How many times did a specific label occur? Pair COUNT(*) with a FILTER (WHERE ...) clause.
Example — count of hallucinated responses

2. Rate (% of total)

What percentage of traffic has a given eval label, status, or attribute? Divide a filtered count by an unfiltered count.
Example — hallucination rate
Filter the denominator to != null so spans without an eval don’t inflate your total.
Example — error rate for a specific tool

3. Weighted composite score

Combine multiple eval scores into one number — useful when quality depends on several dimensions (e.g., correctness and relevance).
Example — 25% QA correctness + 75% relevance
Weights should sum to 1. Scores must be numeric — use .score, not .label.

4. Cost and usage

Turn token counts into dollars, count distinct sessions, and roll them up together or separately. Total cost
Replace 2.5 and 10 with your model’s per-million input/output token rates. Distinct sessions
Cost per session
Evaluation cost estimate — estimate how much it costs to run an eval over your traces
Replace 229 with your eval prompt template’s token length, 104 with the estimated output token length, and the rates with your eval model’s per-token input/output costs.

5. Eval quality against human labels

When you have both auto-evals and human annotations, measure how well the eval matches the human ground truth.
Example — precision of a QA correctness eval
RECALL(...), F1(...), TP(...), FP(...) follow the same signature. See Metric functions below for the full catalog.

AQL syntax

The patterns above cover most cases. When you need to adapt or extend them, this is the full AQL vocabulary. A metric is a single query that aggregates rows from model (the span table). You pick your dimensions, choose an aggregate or metric function, scope which rows count with WHERE or FILTER, and use CASE or operators inside expressions. Each subsection below walks one of those pieces.

Query shape

Every metric starts with this template. SELECT must return one value — there is no GROUP BY in AQL. WHERE scopes the whole query; FILTER (WHERE ...) scopes just the preceding aggregate.

Constants, expressions, and comments

The general building blocks you use inside a query.
  • Constants — numbers (int or float) or strings in single quotes ('active').
  • Expressions — math/boolean operators combining dimensions and constants; no aggregate inside. Can nest: A * (B + C).
  • Comments-- single line (CMD+/) or /* multi-line */.

Dimensions

A dimension is any span property, feature, tag, prediction, or actual — string or numeric. Wrap any column with dots or spaces in double quotes. Here are the ones you’ll reference most on trace data:

Aggregation functions

Reduce many rows to one number. Every metric must have at least one aggregation or metric function.

Metric functions

Beyond basic aggregates, AQL ships pre-built statistical metrics. All take keyword arguments. Omit pos_class= to use the model’s configured positive class. See the concrete example in Common patterns #5.
All four share the signature FUNC(actual=<col>, predicted=<col>).
Normalized Discounted Cumulative Gain. omit_zero_relevance controls whether 0-relevance rows affect averaging.

Filters — WHERE and FILTER

Scope which rows the aggregate sees. WHERE scopes the whole query; FILTER (WHERE ...) scopes just the preceding aggregate. Identical syntax inside. Subqueries are not supported in either.

Conditionals — CASE

Classify rows into buckets before aggregating. Expressions evaluated in order; the first true branch wins. ELSE gives a default — without one and no match, returns NULL.

Operators

Math and comparison building blocks used inside expressions. Numeric — apply to numeric dimensions only. Comparison — apply to strings and numerics.

Next step

You’ve defined what to measure. Now put those metrics on a dashboard so you can see them at a glance:

Next: Set Up Dashboards