Sub topic 4
Packaging Brand Voice and Constraints as Reusable Context
This chapter assumes you can write a basic prompt for a generative AI assistant, and that you have seen a parameterized prompt template like the one in the previous chapter. You should be comfortable reading short Python snippets. The goal here is to move brand voice, audience facts, and hard rules out of individual prompts and into a single context package that every workflow step can reuse.
Why brand context needs its own package
A prompt template holds the instructions for one task. Brand context holds what stays true across many tasks: how the company sounds, who it talks to, which claims it may make, and which words it avoids.
If you paste these rules into every template, three problems appear:
- Drift. The newsletter template says "friendly and plain" while the social template says "upbeat and playful." Nobody decided that. It happened because two people edited two files.
- Slow updates. When legal bans a phrase, you must find and edit every template that mentions it.
- Untestable voice. Voice described loosely in each prompt cannot be checked against anything.
The fix is to keep one source of truth for brand context and have templates pull from it. The brand context is data. The templates are logic that reads the data.
What belongs in a brand context package
Separate the context into parts, because each part changes at a different speed and plays a different role in the prompt.
| Part | What it holds | Changes how often | Example |
|---|---|---|---|
| Identity | Company name, what it sells, one-line positioning | Rarely | "Acme Cycles sells and services commuter bikes." |
| Voice | Tone traits with short descriptions | A few times a year | "Friendly, plain, no hype." |
| Audience | Who reads this and what they care about | Per campaign or segment | "Commuter cyclists who value reliability over speed." |
| Style rules | Concrete, checkable formatting and wording rules | Occasionally | "Sentences under 25 words. Use 'bike', not 'bicycle'." |
| Hard constraints | Things that must or must not appear | When policy changes | "Never promise a specific discount percentage unless it is in the brief." |
| Examples | Short samples of on-brand writing | As better samples appear | Two approved posts |
Hard constraints and style rules deserve extra care. A hard constraint is a rule where a violation is an error, such as a legal disclaimer or a banned claim. A style rule is a preference, such as sentence length. Keeping them apart lets you treat them differently later. Hard constraints are the ones you check with code or a reviewer. Style rules are the ones you tune.
Describe voice with behavior, not adjectives
"Professional but approachable" means something different to every reader, and a model is no exception. Adjectives alone produce generic copy. Better voice guidance has three layers:
- A few traits, limited to three or four.
- What each trait means in practice, stated as things the writer does or avoids.
- Examples, ideally one on-brand and one off-brand version of the same sentence.
A weak voice description:
Voice: friendly and professional.A stronger one:
Voice traits:
- Friendly: address the reader as "you"; allow one light joke per post at most.
- Plain: use words a 12-year-old would know; explain any technical term once.
- Restrained: no exclamation marks, no words like "amazing" or "revolutionary".
On-brand: "Your bike gets a full safety check and a tune-up for $49 this April."
Off-brand: "Don't miss our AMAZING spring blowout!!!"The contrast pair does a lot of work. It shows the model the boundary of the voice, which is harder to describe in words than to demonstrate.
Store the context as data
Keep brand context in a structured file that people can edit without touching code. JSON works, as does YAML if your team already uses it. The example below uses JSON so it needs only the standard library.
{
"version": "2026.11.1",
"identity": {
"brand_name": "Acme Cycles",
"positioning": "Reliable commuter bikes and honest service."
},
"voice": {
"traits": [
"Friendly: address the reader as 'you'.",
"Plain: short words, explain any technical term once.",
"Restrained: no exclamation marks, no hype words."
],
"on_brand": "Your bike gets a full safety check for $49 this April.",
"off_brand": "Don't miss our AMAZING spring blowout!!!"
},
"style_rules": [
"Keep sentences under 25 words.",
"Say 'bike', not 'bicycle'."
],
"hard_constraints": [
"Never state a discount unless it appears in the brief.",
"Never compare Acme to a named competitor."
],
"banned_words": ["amazing", "revolutionary", "game-changing", "blowout"]
}Notice that banned_words is a plain list. The same list can be given to the model as an instruction and used by code to check the output. That dual use is the main reason to keep constraints as data.
Turn the context into a prompt block
Next, write a function that renders the context into a block of text that any template can include. Rendering in one place guarantees every workflow describes the brand the same way.
import json
from string import Template
def load_brand_context(path):
with open(path, encoding="utf-8") as f:
return json.load(f)
def render_brand_block(ctx):
traits = "\n".join(f"- {t}" for t in ctx["voice"]["traits"])
style = "\n".join(f"- {r}" for r in ctx["style_rules"])
hard = "\n".join(f"- {r}" for r in ctx["hard_constraints"])
banned = ", ".join(ctx["banned_words"])
return (
f"Brand: {ctx['identity']['brand_name']}. {ctx['identity']['positioning']}\n"
f"Voice traits:\n{traits}\n"
f"On-brand example: {ctx['voice']['on_brand']}\n"
f"Off-brand example: {ctx['voice']['off_brand']}\n"
f"Style rules:\n{style}\n"
f"Hard constraints (never break these):\n{hard}\n"
f"Never use these words: {banned}."
)
POST_TEMPLATE = Template(
"$brand_block\n\n"
"Task: write a $channel post announcing: $announcement\n"
"Audience: $audience\n"
"Limit: at most $max_words words. End with one call to action."
)
def build_post_prompt(ctx, channel, announcement, audience, max_words):
return POST_TEMPLATE.substitute(
brand_block=render_brand_block(ctx),
channel=channel,
announcement=announcement,
audience=audience,
max_words=max_words,
)The template has one placeholder, $brand_block, for the entire brand context. When the brand changes, you edit the JSON file and every template picks up the change. The substitute() method still raises an error if you forget an input, which is the behavior you want.
Where to place context in the prompt
Placement affects how well the model follows the rules. Three habits help:
- Put stable context first and the task last. The brand block is the same on every run. The task changes. Keeping the stable part at the top also makes it easier to compare prompts between runs.
- Repeat the most critical rule near the task. Models can lose track of a rule buried in a long block. If "never state a discount unless it is in the brief" is essential, restate it in one line next to the task.
- Keep the block short. Every extra rule competes for attention. A block of 15 sharp rules usually outperforms one of 60 vague ones.
Match context size to the step
Not every step needs the whole package. A step that summarizes a brief does not need the banned word list. A step that writes final copy needs all of it. Sending the full context to every step wastes space and can distract the model.
One approach is to render different blocks for different purposes:
def render_block(ctx, parts):
sections = {
"identity": lambda: f"Brand: {ctx['identity']['brand_name']}. {ctx['identity']['positioning']}",
"voice": lambda: "Voice traits:\n" + "\n".join(f"- {t}" for t in ctx["voice"]["traits"]),
"hard": lambda: "Hard constraints:\n" + "\n".join(f"- {r}" for r in ctx["hard_constraints"]),
"banned": lambda: "Never use these words: " + ", ".join(ctx["banned_words"]) + ".",
}
return "\n".join(sections[p]() for p in parts)
# A summarizing step needs only identity.
# A drafting step needs identity, voice, hard, and banned.A reasonable default is to give drafting and rewriting steps the full block, and give analysis steps only identity and the constraints that apply.
Check constraints in code, not only in the prompt
Telling a model "never use these words" lowers the chance of a violation. It does not remove it. Anything you can check mechanically, check after the model responds.
import re
def check_constraints(text, ctx, max_words=None):
problems = []
for word in ctx["banned_words"]:
if re.search(rf"\b{re.escape(word)}\b", text, flags=re.IGNORECASE):
problems.append(f"Banned word used: {word}")
if "!" in text:
problems.append("Exclamation mark found")
if max_words is not None and len(text.split()) > max_words:
problems.append(f"Over {max_words} words")
return problems
draft = "Our amazing spring service is here!"
ctx = {"banned_words": ["amazing", "blowout"]}
print(check_constraints(draft, ctx, max_words=90))This prints ['Banned word used: amazing', 'Exclamation mark found']. The re.escape call keeps a banned phrase containing special characters from being read as a pattern, and \b prevents matching inside longer words.
Some rules cannot be checked this way. "Sounds friendly" and "does not make an unsupported claim" need a human reviewer or an evaluation step, covered in later chapters. Sort your rules into two lists: those code can verify and those a person must judge.
Common errors
- Too many traits. Eight voice traits cancel each other out. Pick three or four.
- Rules without examples. "Be concise" is vague. "Under 25 words per sentence" is checkable.
- Contradictions. "Be playful" and "never use humor" in the same block produce unpredictable output. Review the rendered block as a whole, not each rule alone.
- Stale context. If the file has no version or owner, nobody knows if it is current. Include a
versionfield and note who approves changes. - Copying brand guidelines wholesale. A 40-page style guide is written for humans. Distill it into the few rules that change the output.
- Examples that leak. If your on-brand example is one specific sentence, the model may copy its structure or wording. Offer two or three varied examples, or say that examples show tone only.
- Confidential material in context. Everything in the brand block is sent to the model. Do not include unreleased pricing, client names, or internal strategy unless your tool's data terms permit it. Privacy is covered in a later chapter.
How the pieces fit
Keep the retry count small, such as two attempts. If a draft fails a hard constraint repeatedly, send it to a person instead of looping.
Test a context change like a code change
Changing the brand file changes the output of every workflow that uses it. Before you publish a new version:
- Run a fixed set of test inputs through the old and new context.
- Compare the outputs side by side.
- Run the code checks on both sets.
- Have the brand owner approve the change and update the
versionfield.
The next chapters cover test sets and versioning in detail. For now, treat the brand file as shared infrastructure, not a scratch pad.
Summary of the working model
- Keep identity, voice, audience, style rules, hard constraints, and examples as separate parts of one data file.
- Describe voice through behaviors and contrasting examples, not adjectives.
- Render the context in one function so every template describes the brand identically.
- Put stable context first, repeat critical rules near the task, and keep the block short.
- Send each step only the parts it needs.
- Verify mechanical rules in code after the model responds, and route judgment rules to a person.
Exercise
Your team's newsletter template and social template each contain their own copy of the voice description, and they have started to disagree. Describe how you would restructure them, and name one rule from the brand context that you would check in code and one that you would leave to a human reviewer.
Show answer
Move the voice, style rules, hard constraints, and banned words into one versioned data file (for example JSON), write one render function that turns it into a brand block, and have both templates include that block through a placeholder such as $brand_block. Edits then happen in one place. A rule to check in code: the banned word list, exclamation marks, or a maximum word count, all of which can be tested with string matching. A rule for a human reviewer: whether the post sounds friendly, or whether a claim is supported by the brief, since these need judgment.
Exercise
A draft from your workflow contains the sentence "Our revolutionary tune-up is here!" The banned list contains "revolutionary", and the style rules forbid exclamation marks. Using check_constraints, what two problems are reported, and why is it still worth keeping the banned-word rule in the prompt as well?
Show answer
The function reports "Banned word used: revolutionary" and "Exclamation mark found". The prompt rule is still worth keeping because it makes the model less likely to produce the violation in the first place, which reduces retries. The code check is the safety net for the cases where the model ignores the rule.