Sub topic 2
Packaging Reusable Context in AI Marketing Workflows
Assume you can write basic prompts and read short Python snippets. This chapter focuses on designing a workflow that produces consistent, reviewable marketing content.
Brand voice and constraints
Keep reusable context separate from changing campaign data. Brand context describes how the organization communicates. Constraints define rules the output must follow.
Useful context includes:
- Audience and reading level
- Tone, vocabulary, and banned phrases
- Brand claims that require evidence
- Channel limits, such as email subject length
- Required calls to action
- Privacy and approval rules
Parameterized templates use named placeholders for values that change between runs.
from string import Template
template = Template(
"Write a $channel post for $audience. "
"Use a $voice voice. Mention $announcement. "
"Use no more than $max_words words."
)
prompt = template.substitute(
channel="LinkedIn",
audience="commuter cyclists",
voice="friendly, plain, no hype",
announcement="our spring service discount",
max_words=90,
)
print(prompt)Store the template and brand context in version-controlled files. This makes changes visible and reversible.
Structured output and validation
Ask the model for fields your next step can use. JSON is a common structured format, but it still needs validation. A valid JSON document can contain missing fields, the wrong types, or text that violates limits.
import json
def validate_draft(raw):
data = json.loads(raw)
for field in ("subject", "preview_text", "body"):
if not isinstance(data.get(field), str):
raise ValueError(f"Missing or invalid field: {field}")
if len(data["subject"]) > 60:
raise ValueError("Subject is too long")
return dataChaining steps
A multi-stage workflow passes named outputs into later prompts. Keep each step narrow. For example, one step can summarize a brief, and another can write subject lines from that summary.
Human review checkpoints
Place review before an irreversible or costly action. Review is especially important when content contains claims, personal data, regulated topics, or a public commitment. A validator checks predictable rules; a person checks meaning, accuracy, judgment, and brand fit.
A practical workflow can allow automatic generation and validation, then require approval before sending an email or publishing a post.
Exercise
Where should a human review a workflow that drafts a promotional email?
Show answer
After generation and validation, but before the email is scheduled or sent.