
The problem
Churn is the slow leak that kills SaaS unit economics. Every product team knows it; every retention team knows it; the question is always "which customers are about to churn, and what should we do about them?" Most teams answer this with a mix of usage-decline rules ("logins dropped 50% in the last 30 days") and intuition from the account-management team. Both work to a degree; both also generate false positives that drown the retention team and miss the silent-churn cases that do not show declining usage until the week before cancellation.
The data the prediction needs is already in the product. Usage, support tickets, billing events, feature adoption, contract milestones, contact patterns — all available, all correlated with churn outcomes. The pattern the rules try to encode is a conditional probability — and conditional probabilities have a proper home in a predictive query.
How it works
The system runs _predict churn on each active customer conditioned on the available signals. The result is a probability per customer plus a $why factor decomposition. In the e-commerce demo, each active customer's latest order is scored with _predict churned_in_3_months, learned from the orders whose next three months are known, and _relate over the customers who left names the profiles that churn more (a tenure of 18 months or more, at 1.86×). The retention team works the top-N by predicted churn probability; high-confidence high-risk customers route to senior account managers, mid-confidence customers route to automated outreach (in-app messages, email sequences), low-confidence customers stay un-routed.
The ranked-outreach framing matters because retention is throughput-limited. The retention team can only call so many customers per week. Ranking the queue by value at stake (in the demo, the churn probability × the customer's last-12-month spend) means the team's hours go to the highest-leverage save attempts. Mature deployments combine the prediction with the predicted effect of each outreach action to pick the right one per customer.
{
"from": {
"from": "customer_months",
"where": {
"month": {
"$lte": "2026-01"
},
"purchases": {
"$gte": 1
}
}
},
"where": {
"pets": "small_animal",
"region": "tampere",
"tenure_months_at_month": 8,
"visits": 5,
"purchases": 1,
"spent_eur": 100.95
},
"predict": "churned_in_3_months",
"limit": 2,
"select": [
"$p",
"feature",
{
"$why": {
"highlight": {
"posPreTag": "«",
"posPostTag": "»",
"negPreTag": "‹",
"negPostTag": "›"
}
}
}
]
}For the full architecture, see the technology overview. For the broader narrative across multiple use cases, read The Predictive Application. For the whole picture, see predictive e-commerce.
See it live
This use case runs in the 🛒 E-commerce demo today. Click through to the live application and inspect the queries that produce the result.
Build it with Claude Code
Paste this prompt into Claude Code, or another coding agent, in your own codebase. It runs Aito locally from the Docker image, reads the API docs written for agents, and follows a working reference implementation.
Add win back customers to this codebase using Aito, a predictive database. The feature: rank our customers by how likely they are to stop buying, with the reasons, for outreach. 1. Run Aito locally: `docker pull ghcr.io/aitohq/aito`, then follow https://aito.ai/docker/ to start it with your own API keys (keep them in the environment, never in code). 2. Read https://aito.ai/docs/api/llms.txt for the v2 query shapes before writing any query. 3. Read the use-case guide: https://aito.ai/use-cases/churn-ranked-outreach/ 4. Use this reference implementation as the pattern (schema, data load and queries): https://github.com/AitoDotAI/aito-ecommerce-demo/blob/main/src/churn_risk.py and https://github.com/AitoDotAI/aito-ecommerce-demo/blob/main/data/generate_fixtures.py 5. Find the matching tables in this codebase, design the Aito schema for them (links between tables where we have foreign keys), and load a sample. 6. Measure before wiring the UI: hold out recent closed rows and report the calibration per probability band against the base rate, and how many of the customers who really stopped buying were near the top. 7. In the UI, show the probability ($p) and the reasons ($why) on each row, and flag the rows beyond a threshold I choose for review. Never write the score back as a decision. Ask me before changing anything outside the new feature.
Frequently asked
How does this compare to dedicated churn-prediction tools (Gainsight, ChurnZero)?
Dedicated tools have UI for the retention workflow — case management, playbook orchestration, contact tracking. _predict on subscriptions is the prediction layer; you still need the retention CRM. The two compose: Aito predicts the ranked list, Gainsight/ChurnZero (or a custom workflow) drives the outreach. For teams that want to avoid a separate vendor, the prediction plus a simple ticket-routing workflow is often enough.
What if our churn rate is low (under 5% per year)?
Low churn means few positive examples — the system has less signal to learn from. The conditional probability is still computable but the predictions are less differentiating. Measure the precision of the top of the list with _evaluate on past months before deciding how far down the queue to work. The retention queue is still meaningfully ranked, just with more uncertainty in the tail.
Can the prediction recommend WHICH outreach to use, not just who to call?
Yes, as a second prediction. _predict the chance of an order within 30 days conditioned on the customer's context AND the outreach action, against doing nothing. The result is a per-customer ranking of actions by what they add after their cost; the demo's Retention view shows it beside each at-risk customer. Run both: rank customers by risk × value at stake (which to call), and rank actions by their predicted effect (what to do). The two together drive the retention playbook.
Does this work for one-time-purchase products (not subscription)?
The pattern translates to "predict which customers are about to lapse." For subscription products, lapse is churn. For one-time-purchase products, lapse is "no purchase in N months when historical purchase cadence was M months." Same conditional probability, different definition of the negative outcome. Mature e-commerce deployments use this for win-back ranking.
How quickly does the prediction adapt when our product changes?
New product features, pricing changes, segment shifts — all enter the conditional probability through the data they produce. No retraining schedule. The prediction reflects the most recent N customer cohorts in proportion to their representation in the data. For very abrupt product changes (major UI overhaul, large price change), the prediction quality temporarily drops while the new cohort accumulates — and recovers as the new behaviour accumulates in the data, with no retraining step to schedule.



