Chapter 4 · Assign a role#
The big idea#
A role (“You are a senior database engineer”) changes the vocabulary, depth and priorities of the answer. It works because the model has read how experts in each field write, and the role tells it which voice to use. A role is a lens, not magic: it does not add knowledge the model lacks.
Everyday example: Ask three people to look at the same house: an electrician checks wiring, an estate agent looks at the kitchen, a safety inspector looks for exits. Same house, three different reports. The role decides which things get noticed.
In plain words
Pair a role with a concrete job and an audience: “You are a patient tutor explaining to a 12-year-old” beats “You are a genius”.
A picture#
Before and after#
Replies below are typical examples to show the difference. Your model will word things differently, so run the prompts yourself.
Example 1 · Code review#
Before
Review my SQL query.
SELECT * FROM orders WHERE YEAR(created_at) = 2025;
Typical reply
The query selects all columns from the orders table where the year of created_at is 2025. It looks fine and should return the orders from that year.
After
You are a senior database engineer. Review the query below for speed and correctness on a table with 50 million rows. List problems from worst to least, each with a fix.
SELECT * FROM orders WHERE YEAR(created_at) = 2025;
Typical reply
1. **Function on the column**: `YEAR(created_at)` stops the index being used, so this scans all 50M rows. Use `created_at >= '2025-01-01' AND created_at < '2026-01-01'`.
2. **SELECT ***: fetch only the columns you need.
3. No `LIMIT`/pagination for a result that may be millions of rows.
Prompt checker (code/promptcheck.py, columns T C A F L E D):
before 2/7 [Y . . . Y . .] missing: context, audience, format, example, delimiters
after 4/7 [. Y Y Y Y . .] missing: task, example, delimiters
Why it works. The role brings a checklist (indexes, scans, scale) that the plain request never triggered. The first reply is not wrong, it is shallow.
Example 2 · Explaining#
Before
Explain recursion.
Typical reply
Recursion is a programming technique in which a function calls itself in order to solve a problem by breaking it down into smaller sub-problems, each of which has a base case...
After
You are a patient teacher explaining to a 12-year-old who loves video games. Explain recursion with one game-based analogy and a 4-line Python example. Under 120 words.
Typical reply
Imagine a level that contains a smaller copy of itself, like a door that leads into the same game but one room smaller. You keep walking in until the room is tiny and there is nothing to enter: that is the *base case*, and you walk back out.
```python
def countdown(n):
if n == 0: return
print(n)
countdown(n - 1)
```
Prompt checker (code/promptcheck.py, columns T C A F L E D):
before 1/7 [Y . . . . . .] missing: context, audience, format, limits, example, delimiters
after 4/7 [. Y Y . Y Y .] missing: task, format, delimiters
Why it works. The role sets the reading level, the analogy gives the tone and the limits keep it short. The content is the same; the fit is different.
Roles that work, and roles that do not#
Helpful |
Not helpful |
|---|---|
“You are a code reviewer who cares about security.” |
“You are the world’s best programmer.” |
“You are a customer support agent for a bank.” |
“You are a genius.” |
“You are an editor. Cut the text by a third without losing facts.” |
“You are an AI.” |
A role should change what the model looks for. If it does not, it is decoration.
Rules of thumb#
Pick the role that matches the job, not a famous name.
Add the audience too: who the answer is for.
Roles shape style and focus; still give the facts in the context.
Common mistakes#
Using flattering roles (“world’s best”) and expecting better facts.
Forgetting that the role does not make the model correct. Still verify important claims.
Contradicting the role later in the prompt (“be formal” and “use slang”).
Try it yourself#
Write a role line for reviewing a business contract for hidden costs.
Why might “You are a genius” not help?
Take the SQL review prompt and change the role to a beginner tutor. How should the answer change?
Answers
“You are a careful commercial lawyer reviewing a contract on behalf of a small business owner. Flag any clause that could cost money later.”
It gives no focus or audience. The model has nothing new to look for.
It should explain why each issue matters in simpler words and may show an easier fix first.
Next
You have decided who answers. Next: decide the shape of the answer. Control the format.