How to Auto-Segment Customers Using AI and Klaviyo
Let AI analyze customer behavior and automatically assign segments in Klaviyo.
What This Integration Does
Manual segmentation goes stale fast. A customer who was a VIP three months ago may now be at-risk, and a one-time buyer might be quietly turning into a regular. This workflow runs on a schedule, asks the AI Agent to classify each profile against your taxonomy (VIP, new, at-risk, bargain-hunter, loyal, lapsed), and writes the result back to Klaviyo as a custom property your flows and segments can use.
Each run is incremental - it scopes to profiles updated since the last run, classifies them, and upserts the segment property. Because the property is a single string, downstream Klaviyo segments stay simple: one filter on ai_segment equals vip.
Prerequisites
- A Klaviyo connection with profile read and write access.
- A connection to your store of truth for purchase history (shopify, woocommerce, or your data warehouse).
- A written segment taxonomy with definitions (what makes a profile a VIP vs. loyal vs. at-risk).
Step 1: Schedule Trigger
Add a Trigger node set to Schedule. Daily at 03:00 is a sensible default - the segments are stable enough that hourly is overkill, and daily means flows and campaigns always see fresh tiers in the morning.
Step 2: Pull Profiles to Score
Add a Connector node on klaviyo and use list-profiles. Filter to profiles updated in the last 24 hours, or paginate through everyone on a full weekly re-score. Pair this with shopify list-customers or woocommerce list-customers if you need order history fields that are not already mirrored to the Klaviyo profile.
Step 3: Loop and Compute Features
Wrap the next steps in a Loop. Inside the loop, add a Transform node that computes the input features for the AI:
orderCountlifetimeValuedaysSinceLastOrderaverageOrderValuediscountUsageRate
This is what makes the AI consistent - it gets the same shape of input for every profile.
Step 4: AI Agent Classifies the Profile
Add an AI Agent node with structured output:
{
"segment": "vip | loyal | new | at-risk | bargain-hunter | lapsed",
"lifetimeValue": "number",
"nextPurchaseLikelihood": "high | medium | low",
"reasoning": "string"
}
Prompt: Classify this customer using the taxonomy in the system prompt. Features: {{ features }}. Be conservative - prefer 'loyal' over 'vip' unless the customer is clearly in the top 5 percent of lifetime value.
Step 5: Update Klaviyo Profile
Add a Connector step on klaviyo using update-profile. Set:
ai_segment- the chosen segment stringai_ltv- lifetime valueai_next_purchase- high, medium, or lowai_segmented_at- timestamp
You can also call add-profiles-to-list to push the profile into a Klaviyo list named after the segment, so your flows can listen on list membership.
Step 6: Log Movement for Reporting
Add a final Connector node that writes the (profile id, old segment, new segment, timestamp) tuple into a mongodb collection. Use insert-documents. This makes "who moved from at-risk to lapsed this week" trivially queryable, which marketing teams love.
Tips
- Re-score the full base monthly even if you run daily incrementals - definitions drift and a periodic full pass keeps the segments honest.
- Cache feature computation results in mongodb so you do not recompute lifetime value from scratch every run.
- Start with 3 segments, not 8 - it is easier for the AI and for your campaign team.
Common Pitfalls
- Segment churn - if customers flip between VIP and at-risk every run, your prompt or features are too sensitive. Add hysteresis (require two consecutive runs in the new segment before flipping).
- Rate limits - Klaviyo has per-endpoint quotas. Batch profile updates and stagger if you are scoring tens of thousands.
- Missing data - profiles with zero orders confuse the AI. Pre-filter those into a fixed
newsegment before the AI step.
Testing
Run the workflow manually against a list of 5-10 hand-picked profiles whose segment you already know. Inspect the AI's reasoning output - it should match your expectations. Adjust the prompt and re-run until it does, then turn the schedule on.