← Back to all posts RFM Segmentation + LLM-assisted analysis R F M SQL quintiles LLM layer labels · playbooks plain-language Q&A Champions At-risk Win-back

RFM Segmentation with LLM-Assisted Analysis

Jul 2026 · Data Engineering

RFM segmentation is one of the oldest tricks in customer analytics, and it still earns its keep because it is cheap to compute and maps directly to action. Score every customer on Recency, Frequency, and Monetary value, and you can tell champions from lapsed accounts using nothing but transaction history. What has changed recently is what you can bolt onto the end of it: a language model that turns those score triples into named segments, per-segment playbooks, and plain-language answers — provided you draw a hard line about which side owns the numbers.

This is a practitioner's take on doing RFM with an LLM-assisted analysis layer without letting the model invent anything. The scoring stays deterministic in SQL; the model only ever sees aggregates it is asked to describe, not compute. That division of labor is the whole game. Get it right and you get faster, more consistent segment analysis; get it wrong and you get a confident, wrong number in front of a stakeholder.

Quick answer: Compute R, F, and M and their quintile scores in SQL against your source of truth — never in the model. Then pass the finished, aggregated segment table to an LLM and use it for four things: labeling score triples into named segments, drafting per-segment action playbooks, translating plain-language questions into the aggregate that answers them, and writing first-draft campaign copy. Deterministic code owns every number; the model owns the words about those numbers.

The Deterministic Half: Scoring RFM

The scoring is standard and belongs in the warehouse. From a table of purchase events keyed to a resolved customer, compute the three raw measures, then rank each into quintiles with NTILE(5):

WITH rfm_raw AS (
  SELECT
    customer_key,
    DATE_DIFF(CURRENT_DATE(), DATE(MAX(purchase_ts)), DAY) AS recency_days,
    COUNT(*)                                               AS frequency,
    SUM(purchase_value)                                    AS monetary
  FROM purchases
  GROUP BY customer_key
)
SELECT
  customer_key,
  recency_days, frequency, monetary,
  -- fewer days since last order = higher recency score, so invert
  6 - NTILE(5) OVER (ORDER BY recency_days)  AS r_score,
  NTILE(5)     OVER (ORDER BY frequency)     AS f_score,
  NTILE(5)     OVER (ORDER BY monetary)      AS m_score
FROM rfm_raw

That gives every customer a score triple like 5-4-5 or 2-1-1. The one subtlety worth flagging: recency is inverted — a small recency_days is good, so the freshest buyers must land in the top quintile. Everything downstream depends on that table being correct and reproducible, which is exactly why a language model has no business anywhere near this step.

If you are building this on top of the GA4 export, the recency/frequency/monetary derivation from raw purchase events is covered end to end in GA4 + BigQuery: Customer-Intelligence Pipeline Patterns — this article picks up where that mart leaves off.

The Line You Do Not Cross

The single most important rule of LLM-assisted analytics: the model never computes a metric that reaches a decision. Language models are fluent and unreliable at arithmetic over many rows — they will happily average a column wrong and present it with total confidence. So the boundary is drawn deliberately:

SQL / warehouse R, F, M values quintile scores segment counts & revenue numbers | words LLM layer segment labels action playbooks plain-language answers
Everything that is a number is computed left of the line; everything that is language or judgment lives right of it. The LLM only ever reads the aggregates SQL already produced.

Concretely, that means the model is handed a small, already-aggregated table — segment-level counts, average recency, revenue share — and asked to reason strictly from it. It is never handed raw customer rows, both for accuracy and for privacy. If a number appears in its output, that number must trace back to a cell you gave it.

Where the LLM Actually Earns Its Place

With the boundary set, there are four jobs the model does genuinely well.

1. Labeling segments

Start here

Map score triples to named, defined segments — champions, loyal, at-risk, lapsed — and keep the definitions consistent and documented across runs. The tedious, easy-to-drift part of RFM.

2. Action playbooks

Highest leverage

For each segment, draft the recommended move: nurture, upsell, win-back, or suppress. The model is good at proposing the play; a human approves it.

3. Plain-language Q&A

Analyst multiplier

Translate "which segment is quietly leaking revenue?" into the aggregate that answers it, then explain the result in a sentence a stakeholder reads without a SQL primer.

4. Campaign copy

Activation

Draft the first-pass email or ad copy tuned to each segment's posture — reassurance for at-risk, incentive for win-back, recognition for champions.

A Worked Example

Say the SQL step produced this segment summary. These figures are illustrative — the point is the shape of what the model receives, not the values:

Segment Score pattern Customers Revenue share
ChampionsR 5, F 4–5, M 4–58%41%
LoyalR 3–4, F 4–5, M 3–514%27%
At-riskR 1–2, F 3–5, M 3–511%18%
LapsedR 1–2, F 1–2, M 1–232%4%

Handed that table with an instruction to reason only from it, a well-prompted model returns something like: "At-risk customers are 11% of the base but hold 18% of revenue and their recency has dropped to the bottom two quintiles — this is the segment to prioritize, because these are proven high-value buyers going quiet, not low-value churn. Lapsed accounts are a third of the base but only 4% of revenue; suppress rather than spend on them." Every number in that sentence came from the table. The judgment — prioritize at-risk, suppress lapsed — is the part worth a person's attention, and it is the part the model is genuinely useful for surfacing quickly.

The prompt does the heavy lifting: supply only the aggregate table, instruct the model to reason strictly from it, tell it to say plainly when the data does not support a claim, and forbid it from introducing any figure not present in the input. Then verify each number it echoes against the source before it goes anywhere.

Who Owns What

Task Deterministic (SQL) LLM-assisted
Recency / frequency / monetary valuesYesNever
Quintile scoringYesNever
Segment counts & revenue shareYesNever
Naming & defining segmentsRules possibleBetter fit
Per-segment action playbookYes (human-approved)
Plain-language interrogationYes
Draft campaign copyYes (human-edited)

Guardrails and Dead Ends

Frequently Asked Questions

What is RFM segmentation?
RFM segmentation scores each customer on three dimensions: Recency (how recently they purchased), Frequency (how often they purchase), and Monetary value (how much they spend). Each dimension is typically scored into quintiles from 1 to 5, and the resulting score triples group customers into actionable segments such as champions, loyal, at-risk, and lapsed. It is one of the oldest and most reliable customer-analytics techniques because it needs only transaction history and maps directly to marketing action.
How does an LLM help with RFM segmentation?
The RFM scores themselves are computed deterministically in SQL — the language model never touches the arithmetic. What the LLM adds is the interpretation layer: turning score triples into human-readable segment labels and definitions, drafting a per-segment action playbook, translating a stakeholder's plain-language question into the aggregate that answers it, and writing first-draft campaign copy tuned to each segment. It handles language and judgment; the warehouse handles the numbers.
Can an LLM calculate RFM scores directly?
You should not let it. Language models are unreliable at arithmetic over many rows and will confidently produce wrong aggregates. Compute recency, frequency, and monetary values and their quintile scores in SQL against the source of truth, then pass the finished, aggregated segment table to the LLM for labeling and analysis. The rule is simple: deterministic code owns every number; the model owns the words about those numbers.
How do you stop the LLM from inventing metrics in RFM analysis?
Give the model only the aggregated figures you have already computed, instruct it to reason strictly from the supplied table and to say when the data does not support a claim, and verify any number it echoes against the source table before it reaches a stakeholder. Never send raw customer rows — send segment-level aggregates. Treat the model's output as a draft that a person signs off on, not as a system of record.
What are the standard RFM segments?
Common named segments include champions (bought recently, buy often, spend the most), loyal customers (buy often, high value, slightly less recent), potential loyalists (recent, promising frequency), new customers (very recent, low frequency), at-risk (formerly frequent or high-value but recency is slipping), and lapsed or hibernating (low on all three). The exact boundaries are a modeling choice, and a language model is useful precisely for keeping those definitions consistent and clearly documented.
Is LLM-assisted RFM analysis safe for sensitive customer data?
It can be, if you keep personally identifying data out of the prompt. Work at the segment-aggregate level — counts, average recency, revenue share per segment — rather than sending individual customer records to a model. Decide up front what is retained and who can query it, and prefer a private or self-hosted model for regulated data. The interpretation layer only needs the shape of the segments, not the identities inside them.

Building customer analytics with AI in the loop?

I run a free community for people building real data and AI pipelines — warehouse modeling, segmentation, and AI-augmented analysis done honestly. No course, no paywall, just practitioners shipping.

Join the free AI community →

Related reading: GA4 + BigQuery: Customer-Intelligence Pipeline Patterns — the pipeline that produces the RFM mart this article analyzes. Multi-Model Verification: Catching LLM Hallucinations in Enterprise Reports — the verification discipline that keeps an AI analysis layer honest. AI in Enterprise Data Work — What Actually Ships — where AI adds value in data work and where it stalls. For the hardware side of running models locally, see Blendlogic Tech.

Get the build notes

Real AI experiments — what shipped, what failed, and the setups behind them. Straight to your inbox.

No spam, unsubscribe anytime.

More in AI & Building →