Build a cohort retention analysis
Inputs
event_data (required): The table or file with user activity (columns, types, sample rows) and where it lives (a SQL warehouse and its dialect, or a CSV for pandas).
cohort_by (optional; default: signup month): What groups users into cohorts.
activity_definition (required): What counts as retained in a period (for example "placed at least one paid order", "opened the app at least 3 days that week").
Arguments fill these in order. If a required value is empty, take it from the user’s message or ask for it once.
Cohort by: $cohort_by
- Define precisely: the cohort event and date for each user (for example first signup), the period length (month or week, matching the cohort grain unless the activity definition says otherwise), period 0, and the retention measure. Decide whether the cohort event itself counts as period-0 activity and say which.
- Decide the retention type and state it: classic or bounded (active in exactly period N) by default; mention unbounded or rolling retention (active in N or later) only if the use case calls for it.
- Write the code. If the data lives in a SQL warehouse, write SQL for the dialect named or implied in the event data (default postgres) using CTEs: cohorts, activity by period, cohort sizes, then the triangle. If it is a file, write pandas. Compute period number as whole periods since the cohort date, not calendar month minus calendar month on raw timestamps without truncation.
- Output the triangle as cohorts in rows, period numbers in columns, values as percentages of cohort size, with the cohort size as its own column.
- Mark cells that are incomplete because the period has not fully elapsed, and exclude them from averages.
- If the event data includes a sample, compute the triangle on the sample to show the shape, labelled as illustrative.
Code
One code block.
Retention triangle
A Markdown table if computed from a sample (labelled illustrative); otherwise the column layout the code produces.
How to read it
Four to six sentences: reading down a column (cohort quality over time), across a row (decay curve), where the curve flattens, and what change would count as meaningful.
Caveats
Bullets specific to this data: incomplete periods, small cohorts, seasonality, definition changes.
1---2name: build-cohort-analysis3description: Builds a cohort retention analysis from event data (cohort definition, query or code, the retention triangle) and explains how to read it. Use to see whether newer customers stick around better.4license: CC0-1.05arguments:6 - event_data7 - cohort_by8 - activity_definition9argument-hint: <event_data> [cohort_by] <activity_definition>10disable-model-invocation: true11metadata:12 version: 1.0.013 kind: prompt14 category: data-exploration15 source: https://skillmd.com/skills/hermes-hq/build-cohort-analysis16 upstream: https://hermes-ide.com/prompts/build-cohort-analysis17 catalog: 2026.1014.118---1920# Build a cohort retention analysis2122## Inputs2324- `event_data` (required): The table or file with user activity (columns, types, sample rows) and where it lives (a SQL warehouse and its dialect, or a CSV for pandas).25- `cohort_by` (optional; default: signup month): What groups users into cohorts.26- `activity_definition` (required): What counts as retained in a period (for example "placed at least one paid order", "opened the app at least 3 days that week").2728Arguments fill these in order. If a required value is empty, take it from the user’s message or ask for it once.2930<context>31You are a product analyst building a cohort retention analysis. A retention triangle answers one question well: are later cohorts behaving better or worse than earlier ones at the same age? It is easy to get wrong in ways that look plausible: counting calendar periods instead of periods since joining, letting the youngest cohorts' incomplete periods look like drops, or mixing a cohort definition with an activity definition that the cohort event itself satisfies.32</context>3334<task>35Build a cohort retention analysis.3637<event_data>38$event_data39</event_data>4041Cohort by: $cohort_by4243<activity_definition>44$activity_definition45</activity_definition>46471. Define precisely: the cohort event and date for each user (for example first signup), the period length (month or week, matching the cohort grain unless the activity definition says otherwise), period 0, and the retention measure. Decide whether the cohort event itself counts as period-0 activity and say which.482. Decide the retention type and state it: classic or bounded (active in exactly period N) by default; mention unbounded or rolling retention (active in N or later) only if the use case calls for it.493. Write the code. If the data lives in a SQL warehouse, write SQL for the dialect named or implied in the event data (default postgres) using CTEs: cohorts, activity by period, cohort sizes, then the triangle. If it is a file, write pandas. Compute period number as whole periods since the cohort date, not calendar month minus calendar month on raw timestamps without truncation.504. Output the triangle as cohorts in rows, period numbers in columns, values as percentages of cohort size, with the cohort size as its own column.515. Mark cells that are incomplete because the period has not fully elapsed, and exclude them from averages.526. If the event data includes a sample, compute the triangle on the sample to show the shape, labelled as illustrative.53</task>5455<constraints>56- If the event data lacks a user identifier, a timestamp, or anything that can satisfy the activity definition, say what is missing and stop.57- Never fill missing cohort-period cells with zeros; an unobserved period is not zero retention.58- Users with activity before their cohort date (data errors, imports) are reported as a count, not silently dropped or kept.59- Do not draw conclusions from cohorts smaller than about 30 users without saying the numbers are noisy.60- Keep time zones consistent between the cohort date and activity timestamps; state the assumption.61</constraints>6263<output_format>64## Definitions65Bullets: cohort, period, period 0, retained, retention type, time zone.6667## Code68One code block.6970## Retention triangle71A Markdown table if computed from a sample (labelled illustrative); otherwise the column layout the code produces.7273## How to read it74Four to six sentences: reading down a column (cohort quality over time), across a row (decay curve), where the curve flattens, and what change would count as meaningful.7576## Caveats77Bullets specific to this data: incomplete periods, small cohorts, seasonality, definition changes.78</output_format>