Prompt Engineering· Lesson 6 of 7
- 1Anatomy of a Prompt — What It's Made Of6 min
- 2Few-Shot — Teach by Example7 min
- 3Structured Output — Make It Return JSON7 min
- 4Chain of Thought — Let It Reason Step by Step8 min
- 5Prompt Iteration — Improving It in Passes6 min
- 6Role & Persona — Tell It Who to Be7 min
- 7Prompt Injection Basics — When Input Turns Against You8 min
Role & Persona — Tell It Who to Be
In one line · When you give the model a clear role ('you are an expert code reviewer'), it aligns its tone, level of detail, and priorities to that role.
The same question gets a very different reply if the model is 'a teacher for kids' or 'a lawyer'. The role sets the reply's angle and tone without you re-explaining each time — but keep expectations real: it shifts style and framing far more than it makes the model 'smarter' or more factually accurate.
Like asking the same question to a doctor, a pharmacist, and a nurse — each answers from their angle. The role tells the model which hat to wear.
The role is like the session's initial config: you set it once, and every later reply comes out consistent with it.
'Explain recursion' gives a definition; but 'you are a teacher for a 10-year-old, explain recursion' gives a simple story with a concrete example.
The role usually lives in the system prompt, acting as a fixed frame for every reply in the session. Practically, it tilts the probability distribution toward that role's vocabulary, style, and priorities: a 'code reviewer' leans into security and performance, a 'teacher' simplifies and gives examples. Specific roles ('senior Python reviewer focused on security') work far better than generic ones ('you are an expert') — and a role adds no knowledge to the model; it steers how existing knowledge is presented.
System: You are a senior Python code reviewer. Focus on security
and performance. Be direct, cite the line, suggest a fix.
User: Review this function:
def load(path): return pickle.load(open(path, "rb"))Without the role you get generic notes; with it, the reply zeroes in on the danger of pickle with untrusted input — same knowledge, different focus and priorities.
🧪 Try it yourself: take one question (say, 'review this function') and run it 3 times: with no role, with a generic role ('you are an expert'), and with a specific role with clear priorities. Compare what actually changed between the replies — style and focus, or the factual substance itself?
- Inflated roles ('the smartest expert alive') hoping for higher accuracy — a role shifts style and framing, not capability.
- A role that contradicts the rest of the instructions: 'explain simply for beginners' alongside a request for a deep technical report — the reply ends up torn between the two.
- Cramming the role into every user message instead of setting it once in the system prompt.
A product needing a consistent voice across replies, a review from a specific lens (security, performance, UX), or simplification for a defined audience.
Don't lean on it as an accuracy or safety guarantee: 'you are a security expert' prevents no mistakes, and it substitutes for neither explicit constraints nor real review of the output.