Topic 1 of 5 · 4 min read
Writing behaviour specs for AI features
Goal: Write a behaviour spec for an AI feature with must, should and never rules and an escalation rule, and spot a rule nobody can test.
A behaviour spec says, in rules an engineer can build and test, what an AI feature must do, should do and must never do. A normal spec says "the button saves the form". An AI feature has no single path, so the spec describes a range of acceptable behaviour instead.
Check yourself · 1 of 3
A spec for a support assistant says "The bot should be helpful." What is the main problem with this line?
Why it matters
An AI feature gives a different answer each time it runs. Claude, ChatGPT, Gemini and Copilot all do this. If the spec only says "a helpful support assistant", the engineer has to guess what helpful means, the tester has nothing to mark against, and the first angry customer finds the gaps for you. The spec is where the product manager decides the behaviour on purpose.
How to write one
Start with scope: who uses the feature, and what jobs it covers. Then write three lists.
- Must. Behaviour that has to happen every time. "Must answer only from the help-centre articles it is given."
- Should. Behaviour that is wanted but can bend. "Should reply in the customer's language."
- Never. Lines the feature must not cross. "Never promise a refund. Never give legal advice."
Then cover the cases people forget:
- Uncertainty. What does the feature say when it does not know? Models guess and sound sure, so the spec must say "if the articles do not answer the question, say so and offer a person".
- Escalation. When does it hand over to a human, and with what? Name the triggers (a complaint, a legal threat, two failed answers) and what the human receives.
- Off-topic and hostile input. Someone asks for a poem, or insults the bot, or tries to make it ignore its rules. Say what the reply looks like.
- Tone. Describe it with a test, not an adjective: "no exclamation marks, no blame, one apology at most".
Check each line with one question: could two people read this rule and disagree about whether an output broke it? If yes, the rule is untestable and needs rewriting.
Before and after
Before: The assistant should be friendly, accurate and handle refunds sensibly.
Nobody can test "friendly", "accurate" or "sensibly".
After: Must: answer refund questions only from the current refund policy page. Must: state the 30-day window when it is relevant. Never: promise or approve a refund. Should: reply in two to four sentences. If the question is outside the policy page, say "I am not sure, I will pass you to a colleague" and escalate with the chat attached.
What goes wrong
- Rules are written as adjectives, so every reviewer reads them differently.
- Only the happy path is covered. The first week in production is spent on refusals and angry users.
- Must and never rules collide. "Always answer" and "never guess" cannot both hold when the answer is missing.
- The spec lists behaviour but no escalation, so the feature loops with a customer who needed a person.
Examples
A vague rule rewritten as a testable one
Vague: The assistant should not give bad medical advice.
Testable: Never state a diagnosis, dose or treatment. If a message mentions symptoms, reply with one sentence saying the assistant cannot advise on health, give the clinic's phone number and offer to book an appointment.
The second version tells a tester exactly what to look for in an output.
Escalation rule for a returns assistant
Escalate to a person when any of these is true: the customer asks for a refund outside 30 days, mentions a lawyer or a regulator, or the assistant has failed to answer twice in the same chat. The hand-over includes the chat, the order number and a one-line summary of what the customer wants.
Key points
- A behaviour spec describes a range of acceptable outputs with must, should and never rules, because an AI feature never gives one fixed answer.
- Every rule must be testable: two reviewers reading the same output should agree whether it broke the rule.
- Write down what the feature says when it is unsure, because a model left alone will guess and sound confident.
- Name the escalation triggers and what the human receives, so the hand-over is part of the design.
- Cover off-topic and hostile input in the spec, not after launch.
Common mistakes
- Using adjectives such as friendly, accurate or professional as rules, with no observable test.
- Specifying only the happy path and leaving refusals, off-topic and hostile input to chance.
- Listing must and never rules that cannot both hold when the data is missing, with no rule for which wins.
- Leaving out escalation, so the feature keeps answering when a person should take over.
Check yourself · 2 of 3
Which line is an escalation rule rather than a tone rule or a never rule?
Check yourself · 3 of 3
A user asks a recipe assistant for help writing their tax return. What should the spec have decided in advance?
Practice items, not counted towards your mastery.
Start here
- OpenAI Model Spec (opens in a new tab)DocsFree
A real behaviour spec: rules, defaults and worked examples of good and bad replies, written for a production assistant.
- Develop test cases (Claude docs) (opens in a new tab)DocsFree
Anthropic's guide to turning a goal into specific, measurable criteria and graded test cases.
- Evaluation best practices (OpenAI) (opens in a new tab)DocsFree
OpenAI's advice on designing evals, mixing metrics with human or model grading, and testing on realistic inputs.