Problem
Klaviyo customers build segments of their own customers. A segment is a set of logical conditions over what profiles did or did not do, or over profile properties. Less experienced users do not know how to express a concept as a segment. Experienced users spend hours each week building repetitive segments. The team wanted to let both groups describe a segment in plain text and get a ready definition.
Example from the article: a segment of customers who recently viewed a product but have not purchased it.
Solution in brief
An LLM service splits the request into separate AND/OR clauses, then converts each clause into a JSON fragment in parallel, using small specialised prompts with few-shot examples in the system instruction. The user reviews the result in the segment builder. Quality is checked with a mix of LLM-as-judge and hand-written test cases.
Questions this case answers
- How to convert a free-text request into a strictly structured object with an LLM when the output must follow a fixed schema
- How to validate a generative feature when many different outputs are equally correct and there is no one-to-one ground truth
- How to turn a free-text description of a customer segment into a valid structured segment definition with an LLM?
- How to keep a multi-step LLM pipeline from drifting away from a strict JSON schema?
Tools and methods
- Prompt chaining — many small atomic LLM requests instead of one large one
- Few-shot examples in the system instruction — one narrow expert per subtask
- OpenAI model (ChatGPT) — the underlying LLM; the post does not name the exact model
- LLM evaluating LLM plus hand-designed test cases — pre-release validation suite
Google or a one-time email code. No password.