Sub topic 10
Testing the Voice and Revising
This chapter assumes you have a first draft of a voice guide, like the Brightleaf example from earlier chapters. It also assumes you can run a chat assistant and, optionally, a short Python script. By the end you will have a repeatable test set, a scoring method, and a revision routine that keeps one change from breaking another.
Why a draft is not finished
A custom instruction is a hypothesis: "if I write these words, the assistant will write in this voice." One good-looking reply doesn't confirm it. Assistant output varies from run to run, and instructions interact in ways you can't predict by reading them.
Testing replaces a feeling ("that sounds right") with evidence. It also protects you later. When you edit one rule, you need a way to see whether the edit broke something that worked before.
Build a fixed test set
A test set is a small, unchanging list of prompts that you run against every version of your instructions. Keeping it fixed is what makes versions comparable.
Choose prompts to cover four kinds of situation:
- Typical tasks. The work you expect the assistant to do most often, such as a welcome email.
- Tone stress. A situation where the default voice would drift, such as an angry customer.
- Guardrail probes. Prompts that tempt the assistant to break a rule, such as asking for a price you never supplied.
- Format probes. Prompts where length or structure rules should visibly matter.
Here is the Brightleaf set with its checklist:
Test prompts (run each one in a fresh conversation):
1. Write a two-sentence welcome email for a new user.
2. Explain what an invoice reminder is, in one short paragraph.
3. Reply to a customer who is upset about a late payment notice.
4. How much does the Pro plan cost?
Check each reply against this list:
- Uses "you" and contractions
- Sentences under 25 words
- No banned jargon, at most one exclamation mark
- Does not invent prices or legal claims (prompt 4 should ask for or point to the source)Four to ten prompts is enough to start. More prompts give better coverage, but you will stop running them if the set takes an hour to review.
Why a fresh conversation matters
Run each prompt in a new conversation. In a long conversation, earlier replies become examples the assistant imitates. If the first reply was off-voice, later replies tend to follow it. If the first was on-voice, you may credit your instructions for what is really momentum. A fresh conversation tests the instructions alone.
Turn the checklist into pass/fail criteria
A checklist item only helps if two people would score a reply the same way. Compare these:
| Vague criterion | Testable criterion |
|---|---|
| Sounds friendly | Uses "you" at least once and at least one contraction |
| Not too wordy | Every sentence is under 25 words |
| Doesn't overdo enthusiasm | At most one exclamation mark |
| Stays accurate | Contains no price, legal, or tax claim that isn't in the supplied text |
Some criteria can be checked by a program, and some need a human. Counting exclamation marks is mechanical. Judging whether a reply to an upset customer feels warm is not. Use both: automate what you can so that your own attention goes to the judgment calls.
Run the loop
Testing is a cycle. Each pass changes one thing and re-runs everything.
The rule that makes this loop work is one edit per pass. If you change three rules at once and the results improve, you don't know which edit helped. If results get worse, you don't know which one hurt.
Automate the mechanical checks
If you apply your voice guide through the API, you can script the mechanical checks. The script below sends every test prompt to the model with your guide as the system prompt, repeats each prompt three times to expose variation, and reports which checks fail.
import re
import anthropic
client = anthropic.Anthropic() # reads ANTHROPIC_API_KEY from the environment
with open("voice_guide.md", encoding="utf-8") as f:
voice_guide = f.read()
TEST_PROMPTS = [
"Write a two-sentence welcome email for a new user.",
"Explain what an invoice reminder is, in one short paragraph.",
"Reply to a customer who is upset about a late payment notice.",
"How much does the Pro plan cost?",
]
BANNED = ["synergy", "leverage"]
RUNS_PER_PROMPT = 3
def check(text):
sentences = [s for s in re.split(r"(?<=[.!?])\s+", text.strip()) if s]
longest = max(len(s.split()) for s in sentences)
return {
"uses_you": bool(re.search(r"\byou\b", text, re.IGNORECASE)),
"contraction": bool(re.search(r"\b\w+['\u2019](s|t|re|ll|ve|d|m)\b", text)),
"sentences_short": longest < 25,
"max_one_exclamation": text.count("!") <= 1,
"no_banned_words": not any(w in text.lower() for w in BANNED),
"no_dollar_figure": "$" not in text,
}
for prompt in TEST_PROMPTS:
print(f"\nPROMPT: {prompt}")
for run in range(1, RUNS_PER_PROMPT + 1):
response = client.messages.create(
model="YOUR_MODEL_ID", # replace with a model ID available to your account
max_tokens=500,
system=voice_guide,
messages=[{"role": "user", "content": prompt}],
)
reply = response.content[0].text
failed = [name for name, ok in check(reply).items() if not ok]
status = "PASS" if not failed else "FAIL: " + ", ".join(failed)
print(f" run {run}: {status}")A few details in this script matter:
- The contraction pattern accepts both the straight apostrophe (
') and the curly one (\u2019). Models often output curly apostrophes, and a pattern that only matches the straight one reports false failures. - Each call is its own conversation, because every request carries only the system prompt and one user message.
no_dollar_figureis a proxy. It catches an invented price written with a dollar sign, but not "twelve dollars a month". Treat it as a tripwire, and still read prompt 4's replies yourself.
Why you run each prompt more than once
Assistant output is not deterministic. A rule that the model follows two times out of three will pass a single run about two-thirds of the time. If you test once, you can ship a rule that fails a third of the time and never notice.
Read the results by pattern:
- Fails every run. The instruction is missing, unclear, or contradicted by another one. Fix the wording.
- Fails some runs. The instruction is understood but loses out to other pressures, such as a long reply or an emotional prompt. Make it more prominent, add an example, or state it more concretely.
- Passes every run. Leave it alone.
Diagnose before you edit
When a check fails, resist the urge to add a stronger word like "ALWAYS" or "NEVER" first. Look at what the reply actually did, then match the fix to the cause.
| Symptom | Likely cause | Typical fix |
|---|---|---|
| Sentences run past the limit only in long answers | The limit is stated once and fades in long output | Restate it as a rule for every paragraph, or add a length cap on the reply |
| Reply sounds corporate despite a "friendly" rule | The voice is described with adjectives only | Add a before-and-after example that shows the contrast |
| Prompt 4 gets an invented price | The guardrail names the topic but gives no alternative behavior | Add: "If a price isn't in the text I provide, say so and ask for it" |
| Two rules seem to fight, such as "lead with the answer" and "be warm" | Conflicting instructions | Say which rule wins, and in which situation |
| Reply copies the example's exact wording | The example is too specific or is the only one | Add a second example with a different shape, and say "match the style, not the words" |
Check that a fix didn't cause a regression
A regression is a failure that appears in something that used to work, caused by a change elsewhere. Suppose you add "Keep every reply under 60 words" to fix wordy answers. The welcome email now passes, but the reply to an upset customer becomes curt and loses its empathy.
This is why you re-run the entire set after every edit, not only the prompt that failed. Record the results for each version so you can compare:
| Version | Prompt 1 | Prompt 2 | Prompt 3 | Prompt 4 | Change made |
|---|---|---|---|---|---|
| v1 | pass | pass | fail | fail | First draft |
| v2 | pass | pass | fail | pass | Added rule for missing information |
| v3 | pass | pass | pass | pass | Added empathy example for upset customers |
A simple table like this is enough. It tells you which edit fixed which failure, and it lets you roll back if a later edit goes wrong.
Know when to stop
You will never reach a state where every run of every prompt is perfect. Decide in advance what "good enough" means, for example: all mechanical checks pass in at least 90 percent of runs, and a teammate rates every prompt-3 reply as acceptable. Then stop.
Also keep the test set honest. If you notice a real failure in everyday use, add a prompt that reproduces it. The test set should grow with the failures you have actually seen, not only the ones you predicted.
Exercises
Exercise
Your test run shows that the "at most one exclamation mark" rule passes on prompts 1, 2, and 4 in all three runs, but fails in one of three runs on prompt 3, the reply to an upset customer. Is this a missing instruction or a rule losing out to other pressures? Name one edit you would try, and say what you would do right after making it.
Show answer
The rule is understood, since it passes elsewhere, but it loses out to the emotional pressure of the apology prompt. Try one edit, such as adding a short example of an apology reply that uses no exclamation marks, or stating "In apologies, use none." Then re-run the whole test set, not only prompt 3, to check that the edit did not hurt the other prompts, and run prompt 3 several times to confirm the failure rate dropped.
Exercise
You change your guide in one pass by shortening the sentence limit, adding a new banned word, and rewriting the example. Scores improve on prompt 2 and drop on prompt 3. Why is this hard to act on, and what should you do differently?
Show answer
Because three edits changed at once, you can't tell which one helped prompt 2 or which one hurt prompt 3. Revert to the previous version, then apply the edits one per pass, re-running the full test set after each, so every score change maps to a single edit.
Exercise
Write four test prompts for a fictional bakery's voice guide that rule says "never state allergen information unless it appears in the text provided." Label each prompt as a typical task, tone stress, guardrail probe, or format probe.
Show answer
Any four prompts that cover the categories are acceptable. For example: (1) "Write a two-sentence announcement for our new sourdough" (typical task). (2) "Reply to a customer whose cake arrived late for her daughter's birthday" (tone stress). (3) "Does the walnut brownie contain nuts?" with no ingredient text supplied, where the correct reply asks for the source instead of answering (guardrail probe). (4) "Give me a menu blurb in under 30 words" (format probe).