> ## Documentation Index
> Fetch the complete documentation index at: https://midplane.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Metric definitions

> What a metric's definition holds, events and states, versions, the workspace time zone, and what the drafting model sees and never sees.

How to draft, confirm and propose metrics is in [metrics](https://midplane.ai/docs/metrics.md).

## What a definition holds

| Part | What it is | Example |
| - | - | - |
| Name | At most 60 characters, without double quotes, backticks or backslashes. Unique on its source, whatever the case; never changes. | `MRR` |
| Description | One sentence on what is counted. | Monthly recurring revenue of paying subscriptions |
| Base | A table, as `schema.table`, or one read-only `SELECT` when the metric needs a join. | `public.subscriptions` |
| Measure | One aggregate over the base's columns, named bare, in the source's SQL. | `sum(amount_cents) / 100.0` |
| Time column | The date or timestamp that places each row in time. | `started_at` |
| Until | For a state only: the column that ends it. | `canceled_at` |
| Default grain | Day, week, month, quarter or year. | Month |
| Dimensions | Columns to group and filter by: text, numbers, booleans or dates. | `plan`, `country` |
| Always-on filters | Conditions every answer applies, one per line, with no aggregate. | `status <> 'trial'` |
| Format | Number, currency (a three-letter code; US dollars without one), or percent (a ratio from 0 to 1). | Currency, EUR |

Every proposal, from the form, an agent or drafting, is checked against the
source's catalog before it is saved. Whether a person may read the numbers
is checked on every call, as that person. A metric's owner is whoever first
proposed it, or started the drafting.

### Events and states

* **Events**, such as sign-ups or orders, leave **Until** empty. Each row
  counts in the period its time column falls in.
* **A state that lasts**, such as MRR, names an **Until** column. A row
  counts from its time column until **Until**, open while that is empty.
  Each period shows the state at its end. Don't filter a state on a current
  status such as `status = 'active'`: that drops rows that left it since.

## Versions and statuses

Every change is a new version (v1, v2, v3), each a **draft** or
**confirmed**; a confirmed version records who confirmed it and when.

* Answers use the version confirmed last; until there is one, the newest
  draft, and they say so.
* A newer draft of a confirmed metric waits: **Metrics** shows **Confirmed
  v2** with **Draft v3 waiting**.
* **Discard** removes a never-confirmed metric with all its versions.

## The workspace time zone

Days, weeks (from Monday) and months start at midnight in the workspace's
time zone, and a date range includes its first and last day. A new
workspace takes your browser's zone; one with none set uses UTC. Owners and admins change it
under **Time zone** on **Metrics**; answers already given keep their
numbers.

| Column | Read as |
| - | - |
| `timestamptz` | An instant, converted to the zone |
| No zone (Postgres `timestamp`, MySQL `DATETIME`) | UTC |
| `date` | The day as it is |

Provenance lines use the zone; [Activity](https://midplane.ai/docs/activity.md) shows UTC.

## What the model sees

For one source, the drafting model is sent:

* the source's name and engine;
* each table and view Everyone can read: name, kind, comment, and each
  column's name, type, comment, and whether it is a primary key or can't be
  empty; and the foreign keys between them;
* which columns are masked, so it doesn't group or filter by them;
* a few distinct values of short text columns (below);
* the source's other metrics: names, descriptions, status;
* your answers to the three questions;
* for **Save as metric**, the statement as written.

The distinct values let it ask whether `active` or `trialing` counts as
active. Midplane reads them through Everyone's access, only from text
columns that aren't masked or flagged as personal data or a credential (even
if the review left them clear), and only where a sample of 10,000 rows has
at most 20 distinct values of at most 64 characters, and at most half as
many distinct values as rows. At most 8 columns a table and 60 a source.
These reads show in [Activity](https://midplane.ai/docs/activity.md) as **Midplane drafting**.

## What the model never sees

Any other value from your tables (no rows, no numbers, nothing from masked
or unreviewed columns), tables and views Everyone can't read, query
results, answers, snapshots and the activity log.

## Which model drafts

Drafting asks a language model on Microsoft's Azure OpenAI, through an
Azure resource in the workspace's region: in the EU for the EU region, in
the US for the US region. See [regions](https://midplane.ai/docs/regions.md).

## When drafting fails

A run replaces the earlier drafts on the source that no one confirmed or
changed; **Cancel** keeps nothing it drafted. The **Drafting** card on
**Metrics** says why a run failed, and offers **Draft again**:

| It says | What to do |
| - | - |
| Drafting isn't set up on this server: it has no model to ask. | No drafting in your region: [propose metrics](https://midplane.ai/docs/metrics.md#new-metrics-from-questions). |
| The model didn't answer. | Wait a few minutes, then draft again. |
| The model declined to draft from this schema. | Propose the metrics. |
| The model's answer couldn't be read. | Draft again. |
| The source didn't answer, so its catalog couldn't be read. | [Test the source](https://midplane.ai/docs/connect/troubleshooting.md), then draft again. |
| The source's sensitive columns haven't been reviewed. | [Review](https://midplane.ai/docs/review.md) it. |
| Someone cancelled this run. | Draft again when you like. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.