Sub topic 13
Using Generative AI for Content Variants
This chapter assumes you have read the chapters on dynamic content, modular content with fallbacks, and decisioning. You should be comfortable reading short Python scripts and know what a template slot is. Here you will learn where generative AI fits in a personalisation programme, how to keep it inside safe limits, and how to test its output like any other content variant.
Where generative AI fits
Earlier chapters treated content as something people write once and a template fills in. Generative AI changes the supply side. A language model can draft many versions of a subject line, a product blurb or a call to action in minutes. It does not change the rest of the system. Segments still decide who sees what, templates still define the structure, and decisioning still picks a variant.
Treat the model as a variant factory. It produces candidates. Your pipeline then filters, reviews, tests and serves them. The model should not write straight to a customer's inbox.
There are three common roles for a model:
- Drafting variants for a segment. You give the model a brief, such as "lapsed customers, tone: warm, goal: return to basket", and get ten subject lines back.
- Rewriting a module. You take an approved block and produce shorter, longer or differently toned versions of it.
- Filling a slot at send time. The model writes a sentence for one customer using their data. This is the riskiest role, because no human reviews the result before it is sent.
For most programmes, the first two roles give most of the benefit at a fraction of the risk. Generating text at send time is worth considering only when you have automated checks you trust.
Writing a good brief
The quality of generated variants depends mostly on the brief. A weak brief such as "write an email subject line" produces generic text. A useful brief has these parts:
- Audience description. Use the business name of the segment and what it means ("lapsed: bought before, nothing in 60 days"). Do not paste raw customer records.
- Goal. One action, such as "return to the basket".
- Tone and style. Length limit, reading level, words to use or avoid.
- Hard constraints. Claims you may not make, legal wording that must appear, banned phrases, required placeholders.
- Examples. Two or three approved past variants, so the model matches your voice.
Ask the model for a fixed output format, such as a JSON list, so that code can read the result. Request a small number of variants per segment. Ten reviewed variants are more useful than a hundred that nobody checked.
Keeping personal data out of prompts
Consent and privacy constraints apply to prompts too. A prompt that includes a name, email address or purchase history sends personal data to a model provider. Before you do that, check three things: whether the customer's consent covers this use, whether your contract with the provider limits retention and training on your data, and whether the data leaves the region you are allowed to store it in.
The safest pattern is to generate variants for a segment, not for a person. The model sees the segment description. The customer's own data is added later by the template, through slots that you control. That gives you the benefit of generated language without sending personal data to the model.
Automated checks before any human sees a variant
Models produce fluent text that can still be wrong. Run cheap, deterministic checks first, so reviewers spend time only on candidates that pass. Typical checks are:
- Length. Subject lines that are too long are truncated by mail clients.
- Required and banned content. Legal wording is present. Banned claims such as "guaranteed" or "free" (where not true) are absent.
- Placeholder integrity. Every slot is written as your template expects, and no unknown slots appear.
- Duplicates. Near-identical variants waste test traffic.
- Sensitive inference. The text does not hint at health, finances, family status or other traits the customer did not share.
The following script checks generated variants against a simple rule set. It uses only the standard library, so it runs as written.
import re
ALLOWED_SLOTS = {"first_name", "product_name"}
BANNED_PHRASES = ["guaranteed", "risk-free", "last chance ever"]
MAX_LENGTH = 60
SLOT_PATTERN = re.compile(r"\{\{\s*(\w+)\s*\}\}")
def check_variant(text):
"""Return a list of problems found in one generated variant."""
problems = []
if len(text) > MAX_LENGTH:
problems.append(f"too long ({len(text)} > {MAX_LENGTH})")
lowered = text.lower()
for phrase in BANNED_PHRASES:
if phrase in lowered:
problems.append(f"banned phrase: {phrase}")
for slot in SLOT_PATTERN.findall(text):
if slot not in ALLOWED_SLOTS:
problems.append(f"unknown slot: {slot}")
return problems
candidates = [
"{{ first_name }}, your basket is waiting",
"Guaranteed savings on {{ product_name }} for you today and only today",
"Hi {{ nickname }}, come back for {{ product_name }}",
]
approved = []
for text in candidates:
problems = check_variant(text)
if problems:
print("REJECT:", text, "->", problems)
else:
approved.append(text)
print("Approved:", approved)The second candidate fails on length and a banned phrase. The third fails because nickname is not an allowed slot. Only the first reaches human review.
Human review and brand risk
Automated checks catch rule violations. They cannot judge whether a line is tasteful, accurate or on brand. Keep a human approval step for every variant that enters the library. Reviewers should see the segment, the goal and the variant together, and should be able to reject with a reason. Record who approved what and when. This audit trail matters later, when someone asks why a customer received a certain message.
Common failure modes to watch for:
- Invented facts. The model writes a discount, deadline or product feature that does not exist. Constrain it to facts supplied in the brief, and have reviewers check each claim.
- Tone drift. Variants for different segments end up sounding like different companies.
- Stereotyping. A prompt such as "write for young customers" can yield clichés or exclude people. Describe behaviour and needs, not demographic assumptions.
- Over-familiarity. Text that sounds as if it knows too much feels intrusive. This links to the governance chapter on over-personalisation.
Serving generated variants through decisioning
Once variants are approved, they are ordinary content. Put them in the library with a segment tag, a module name and a version. The decisioning layer treats them like any other options. An epsilon-greedy bandit, as shown in the decisioning chapter, can allocate traffic among them and shift toward the winner.
Generated variants have one practical effect on a bandit. Because it is cheap to create many candidates, you can end up with more arms than your traffic can evaluate. If a segment has 2,000 sends a week and you load 40 variants, each arm gets about 50 sends, and click rates will be mostly noise. Limit the active set to a number that your traffic supports, and retire the weakest arms regularly.
Also keep a human-written control in every test. The question to answer is not "which generated variant wins" but "do generated variants beat what we had". Without a control you cannot tell whether the model added value.
| Question | Practical answer |
|---|---|
| How many variants per segment? | Few enough that each gets enough sends to compare. Start with 3 to 5. |
| Who writes the control? | A person, using your current best copy. |
| When do you retire a variant? | When it trails after a minimum number of sends, or when its facts go stale. |
| What do you log? | Prompt version, model version, reviewer, approval date, variant text. |
Reproducibility and versioning
Model output changes between runs and between model versions. If you cannot say which prompt and model produced a variant, you cannot reproduce it or investigate a problem. Store the prompt text, the model identifier and the settings next to each variant. When you change the prompt or switch model versions, treat the new output as a new batch that needs its own checks and review. Do not assume that a prompt that worked last quarter behaves the same way now.
Send-time generation: when it is justified
Generating text for each customer at send time has real costs. Latency can delay sends. Output cannot be reviewed beforehand. A model outage can break a campaign. Cost grows with every message. Compared with a library of approved variants, you lose control and gain only a little freshness.
If you do use it, apply these safeguards:
- Use only fields you have consent to use, and pass the minimum.
- Run the same automated checks on every output before sending.
- Define a fallback, such as an approved static variant, for when a check fails or the model does not respond in time.
- Sample outputs daily for human review.
- Include a holdout group that receives the static version, so you can measure whether generation adds incremental lift.
This is the same fallback principle from the modular content chapter, applied to a less predictable source.
Common mistakes
- Judging variants by how good they read rather than by how they perform in a test.
- Putting personal data in prompts when a segment description would do.
- Skipping the control group.
- Loading more variants than traffic can evaluate.
- Not recording the prompt and model version.
- Letting generated claims reach customers without a fact check.
Exercise
A team generates 30 subject line variants for a segment that receives 1,500 sends a week and sends them all through an epsilon-greedy bandit. Name two problems with this setup and one change to fix each.
Show answer
First, each variant gets about 50 sends a week, so click rates are too noisy to compare. Fix this by limiting the active set to 3 to 5 variants and retiring weak ones. Second, there is no human-written control, so the team cannot tell whether generated variants beat current copy. Fix this by including the current best subject line as a control arm, or as a holdout. A further valid problem is that no review step is mentioned, which can be fixed by running automated checks and human approval before variants enter the library.
Exercise
Why is it safer to generate variants for a segment than for each customer, and how does the customer's name still appear in the final message?
Show answer
A segment-level prompt contains only a description of the group, so no personal data is sent to the model provider, and every variant can be checked and approved before sending. The name appears because the approved text contains a template slot such as {{ first_name }}, which the template engine fills at send time, using a default value when the name is missing.