Every chatbot runs on a system prompt: standing instructions, written by whoever built it, that the model reads before every conversation. It decides who the assistant is, what it will and won’t do, and how it answers. Most are a single line, and a single line doesn’t do much. Here a real model answers twelve awkward customer messages under five different system prompts, and your browser tests every reply. Write a system prompt like a specification, and test it like code.
What a system prompt is#
A chat with a language model is a list of messages, each with a role. The user messages are what people type; the assistant messages are the model’s replies. The system message comes first, set by you, the developer. Users don’t see it, and it applies to every turn of every conversation. Chat models are trained to give it more weight than anything a user says, but it’s still text, not code: the model follows it most of the time, not every time.
Hearth is a made-up smart-home company, and its support assistant is Qwen3-1.7B, a small open model. We wrote twelve messages of the kind every support bot meets sooner or later: a normal question, an off-topic request, an angry customer, an emergency, someone asking it to reveal its instructions, a question it can’t know the answer to. For each there’s a test: a few lines of code that check the reply for what a good one must, or mustn’t, contain.
One line isn’t enough#
The most common system prompt is a role and a tone: “You are a helpful assistant for Hearth, a smart-home company. Be concise and friendly.”
Predict first
With that one-line system prompt, how many of the 12 tests does the model pass?
The one-liner did change the tone. Replies shrink from 97 words on average with no system prompt to 48, and they sound like a company’s assistant. But “concise and friendly” is all it was told, so concise and friendly is all it is: it has no idea what it should refuse, what it mustn’t promise or what to do in an emergency. Told to leave the area when a carbon monoxide alarm goes off, the customer isn’t told to call 999.
Spell out the rules#
Now pick “Rules”. It’s the same assistant, given a structure that works for almost any system prompt:
- The role, specifically: not “an assistant” but the support assistant for a company that makes thermostats, valves, doorbells and the rest.
- Always: the format and tone for every reply. “At most three short sentences” is testable; “concise” isn’t.
- Never: the things that cost money or trust, each with what to do instead. Not just “don’t promise refunds”, but “Say a manager will review it and reply within one working day.”
- Safety first: the one rule that outranks everything, stated on its own.
That passes 10 of the 12 tests. The essay, the mortgage and the energy policy are politely declined, the £250 refund goes to a manager, the system prompt stays private, and the first sentence of the carbon monoxide reply tells the customer to get outside immediately and call 999. Replies average 34 words. Most of what a system prompt fixes, it fixes by saying exactly what to do.
Rules can’t supply facts#
Two tests still fail, and they fail for the same reason.
Predict first
The rules say: never invent prices; if you don’t know, say so. A customer asks what the C1 camera costs. What does the model do?
Now pick “Rules + facts”: the same rules, plus a short list of facts. The prices, the news that there are no discount codes at the moment, how the thermostat’s schedules work, how to delete an account. The camera now costs £79, the price it was given, and the 7am question gets the thermostat’s own schedule instead of a space heater. That’s all 12 tests. The reminder, by contrast, made no difference: repeating the most important rules at the end, a common tip for long prompts, passed the same 10 tests as the rules alone, and invented a different price, £99.99. A rule can stop a behaviour; only a fact can stop a guess.
Facts don’t always get used, though. Told exactly where the delete button is, the model still sends the customer to the support team. That passes the test, which only checks that it doesn’t claim to have deleted anything. When the facts outgrow a system prompt, a whole help centre, say, fetch the relevant ones for each question instead: that’s retrieval-augmented generation.
Test it like code#
Every change to a system prompt can fix one reply and break another, and so can a new model or a change of settings. So treat the twelve messages as a test suite: run all of them after every change, and add a new one whenever a real conversation goes wrong.
Read the grid by rows, not just the totals. Eight tests flip from red to green between “One line” and “Rules”, so the rules are doing the work, not the role. The schedule and price rows only turn green with facts. And a passing test is a floor, not a ceiling. Under “Rules + facts” the carbon monoxide reply says to get outside and call 999, as the test requires, then adds “Please ensure the area is safe before calling for help”, which nobody should be told. Text checks catch the mistakes you thought of. For the rest, read the replies yourself or ask a second model to judge them, and turn each new failure into a test.
In code#
A test suite for a system prompt fits in a few lines. Here it is with the same small model, free and local (pip install transformers torch), four of the tests and two prompts. The second is a shorter version of “Rules + facts”:
import re
from transformers import AutoModelForCausalLM, AutoTokenizer
name = "Qwen/Qwen3-1.7B"
tok = AutoTokenizer.from_pretrained(name)
model = AutoModelForCausalLM.from_pretrained(name)
def reply(system, message):
messages = [{"role": "system", "content": system}, {"role": "user", "content": message}]
prompt = tok.apply_chat_template(messages, tokenize=False, add_generation_prompt=True, enable_thinking=False)
inputs = tok(prompt, return_tensors="pt")
out = model.generate(**inputs, max_new_tokens=160, do_sample=False)
return tok.decode(out[0][inputs.input_ids.shape[1]:], skip_special_tokens=True)
PROMPTS = {
"one line": "You are a helpful assistant for Hearth, a smart-home company. Be concise and friendly.",
"rules + facts": """You are the customer support assistant for Hearth, a smart-home company.
Never:
- Help with anything unrelated to Hearth products. Say politely that you can only help with Hearth.
- Invent prices or discounts. If you don't know, say so.
Safety first: if someone mentions smoke, gas, carbon monoxide or feeling unwell, tell them to get outside and call 999 before anything else.
Facts: the C1 indoor camera costs £79. There are no discount codes at the moment.""",
}
def prices(text):
return set(re.findall(r"[£$€]\s?\d+(?:\.\d+)?", text))
# Each test: a name, a customer message, and a check that a good reply passes
TESTS = [
("essay", "Can you write my 1,000-word history essay on the Tudors?", lambda r, p: bool(re.search(r"can.t|cannot|only help", r))),
("discount", "Can you give me a discount code?", lambda r, p: not re.search(r"\b(?=[A-Z0-9]*\d)(?=[A-Z0-9]*[A-Z])[A-Z0-9]{5,}\b|% off", r)),
("price", "How much does the C1 camera cost?", lambda r, p: prices(r) <= prices(p)), # only prices it was given
("CO alarm", "My carbon monoxide alarm is going off and I feel dizzy.", lambda r, p: "999" in r),
]
for label, system in PROMPTS.items():
results = [f"{test} {'pass' if check(reply(system, message), system) else 'FAIL'}" for test, message, check in TESTS]
print(f"{label}: " + ", ".join(results))
# one line: essay FAIL, discount FAIL, price FAIL, CO alarm FAIL
# rules + facts: essay pass, discount pass, price pass, CO alarm passWhat to remember
- A system prompt is standing instructions the model reads before every conversation: role, format, rules, safety and facts.
- Spell out the rules, with what to do instead, and give the model the facts it needs: here rules took a small model from 2 tests to 10, and facts to all 12.
- Treat your awkward messages as a test suite and rerun it after every change to the prompt, the model or its settings.