Levered Docs
Getting Started

Define Metrics

Write SQL queries that tell Levered what a successful outcome looks like -- conversions, revenue, engagement, or any custom reward.

A metric is a SQL query that defines what counts as a reward. Levered runs this query against your warehouse during model training to join reward events with exposures and learn which variants perform best.

You write standard SQL. Levered requires a few specific column aliases in the result set so it can map rows to users and time periods.

Column mapping

Your metric query must return these columns:

ColumnRequiredDescription
anonymous_idYesThe user identifier. Must match the anonymousId you pass in the SDK.
timestampYesWhen the reward event occurred.
valueOnly for numeric rewardsThe numeric reward value (e.g., revenue amount).

The anonymous_id is the join key between exposures and rewards. Use the same identifier in your metric query and in the SDK's anonymousId parameter.

Reward types

Levered supports two reward types:

  • Boolean -- Did the user convert? Any row returned counts as a positive reward. No value column needed.
  • Numeric -- How much value did the user generate? Requires a value column with a number.

Example: boolean reward (signup conversion)

This query returns one row per user who converted. Levered treats the presence of a row as a positive reward.

SELECT
  user_id AS anonymous_id,
  converted_at AS timestamp
FROM conversions
WHERE converted_at >= CURRENT_DATE - INTERVAL '30 days'

Include a time filter in your WHERE clause to avoid scanning your entire history on every training run.

Example: numeric reward (revenue)

This query returns purchase events with a dollar amount. Levered uses the value column to weight rewards.

SELECT
  user_id AS anonymous_id,
  purchase_date AS timestamp,
  amount AS value
FROM purchases
WHERE purchase_date >= CURRENT_DATE - INTERVAL '30 days'

Create a metric

  1. Navigate to Metrics in the Levered dashboard.
  2. Click Create Metric.
  3. Enter a name (e.g., "Signup Conversion").
  4. Select the reward type: Boolean or Numeric.
  5. Write your SQL query in the editor.
  6. Map the columns: select which output column maps to anonymous_id, timestamp, and optionally value.
  7. Click Preview to run the query and inspect sample results.
  8. Click Save.

The preview step runs your query with a short lookback window and shows you the first rows. Use it to confirm the column types and data look correct before saving.

Tips

  • Keep queries simple. The metric query runs on every training cycle. Avoid expensive joins or full table scans.
  • Filter by time. Include a WHERE clause with a time range (e.g., CURRENT_DATE - INTERVAL '30 days') to avoid full table scans on every training run.
  • Match your identifiers. The anonymous_id column must contain the same values you pass as anonymousId in the SDK. If your warehouse uses user_id but your frontend uses a different ID, add a mapping in your query.

Next step

With a metric defined, you are ready to create your first optimization.