Role Prompting and Persona Instructions
What Is Role Prompting? Role prompting means telling the model to take on a specific role, perspective, or area of expertise while performing a task.
You are a senior Django developer reviewing code written by an intern. Persona instructions go further: they define a consistent character for an assistant, including its name, tone, responsibilities, and boundaries, usually for a product such as a support chatbot.
You are "Guru", the learning assistant for GOCOURSE. You help students understand course material in simple language. You are patient and encouraging, and you never complete graded assignments for students. Role Prompt Persona Instructions Purpose Shape how one task is approached Define consistent assistant behavior across many conversations Scope Usually one task or prompt An entire application Typical content Expertise and perspective Name, purpose, tone, scope, boundaries, escalation rules Where it lives Instructions for a task System/developer instructions Why Roles Change the Output A role works by changing which kinds of responses become likely (Lesson 2). A role implies:
A Role Implies... Example: "Security reviewer" Priorities Look for vulnerabilities before style Vocabulary Terms such as injection, authentication, input validation Standards What counts as acceptable or risky Audience assumptions Writing for developers, not beginners Format habits Issue, risk, recommendation Example: Same Question, Different Roles Question:
Should we store user session data in localStorage? As a beginner-friendly tutor:
You are a tutor for students learning web development for the first time. Answer in simple language with an everyday analogy. The answer explains what localStorage is, compares it to a notebook anyone using the browser can read, and gives a simple recommendation.
As a security reviewer:
You are an application security reviewer. Evaluate the risks and give a recommendation for a production web application. The answer focuses on the risk that any JavaScript on the page, including injected scripts from a cross-site scripting (XSS) vulnerability, can read localStorage, and recommends alternatives such as server-managed sessions with HttpOnly cookies, while noting the trade-offs.
Both answers are correct. The role determined which aspects mattered and how they were explained.
What Role Prompting Can and Cannot Do What It Does Well Sets perspective and priorities. A reviewer finds problems; a teacher explains; a copywriter persuades. Sets tone and vocabulary. Formal, friendly, technical, or simple. Sets audience assumptions. An "expert speaking to experts" skips basics; a "tutor" explains them. Creates consistency across many responses in an application. What It Does Not Do It does not add knowledge. Writing "You are a world-class tax expert" does not give the model tax rules it lacks, or knowledge of recent changes in tax law. It does not guarantee accuracy. Evidence on whether labels such as "You are an expert" improve factual accuracy is mixed, and the effect varies between models and tasks. Treat role prompts as a way to shape perspective and style, not as a way to make answers more correct. It does not replace specific instructions. "You are an experienced editor" is weaker than "Shorten each paragraph to under 60 words and remove repeated points." The Practical Rule Use a role to set the perspective. Use instructions, context, and data to define the work.
Writing an Effective Role Weak Role You are an expert. This gives no perspective: expert in what, for whom, with what priorities?
Effective Role You are a technical interviewer at a product company, evaluating answers from candidates applying for junior backend developer roles. What Makes It Effective Element In the Example Effect Function Technical interviewer Evaluates rather than teaches Context Product company Practical, industry-oriented standards Audience Junior backend candidates Appropriate expectations for the level Task framing Evaluating answers Implies criteria and judgment Role Plus Task Instructions A role should be followed by concrete instructions:
You are a technical interviewer at a product company, evaluating answers from candidates applying for junior backend developer roles.
Evaluate the candidate's answer to the question below.
- List what the answer gets right.
- List what is missing or incorrect.
- Give a score from 1 to 5, where 3 means acceptable for a junior role.
Question: What is the difference between authentication and authorization?
Authentication is logging in. Authorization is when you have a token. The role sets expectations for a junior-level evaluation; the numbered instructions define the exact output.
Audience Roles: Telling the Model Who It Is Talking To Sometimes the most useful role is not the model's role, but the reader's.
Explain database indexing to a shop owner who manages inventory in Excel and has never written code. This often works better than "You are a friendly teacher", because it tells the model exactly what the reader already knows, which controls vocabulary and examples. The two approaches can also be combined: a role for the model and a description of the audience.
Persona Instructions for Applications A persona defines how an assistant behaves across every conversation. A complete persona usually covers six areas.
- Identity and Purpose You are "Guru", the learning assistant inside the GOCOURSE platform. Your purpose is to help enrolled students understand course material.
- Audience Users are college students and recent graduates in India, mostly beginners in programming. Many use English as a second language.
- Tone and Style Be patient, encouraging, and clear. Use simple English and short paragraphs. Use code examples when they help. Avoid slang and sarcasm.
- Scope: What the Assistant Does You can:
- Explain programming concepts from the student's course
- Help find and understand errors in the student's code
- Suggest practice exercises
- Boundaries: What the Assistant Does Not Do You do not:
- Write complete solutions for graded assignments; give hints and explanations instead
- Answer questions about payments, refunds, or certificates; direct these to support
- Give opinions on topics unrelated to learning and technology
- Escalation and Uncertainty If you are not sure about an answer, say so and suggest checking the official documentation or asking a mentor. For account or payment questions, reply: "Please contact support@gocourse.example for help with your account." Why Boundaries Matter Most Without explicit boundaries, a helpful assistant will attempt everything, including tasks it should not do, such as completing graded assignments or inventing a refund policy. Boundaries protect users, the business, and the learning goal of the product.
Implementing a Persona in Python Keeping persona parts as structured data makes them easy to review, change, and reuse.
Requirements: pip install openai and an OPENAI_API_KEY environment variable.
from dataclasses import dataclass
from openai import OpenAI
client = OpenAI() MODEL = "gpt-5.4" # Replace with a model available in your account
@dataclass class Persona: name: str purpose: str audience: str tone: str can_do: list[str] cannot_do: list[str] fallback: str
def to_instructions(self) -> str: can = "\n".join(f"- {item}" for item in self.can_do) cannot = "\n".join(f"- {item}" for item in self.cannot_do) return ( f"You are {self.name}. {self.purpose}\n\n" f"Audience: {self.audience}\n\n" f"Tone and style: {self.tone}\n\n" f"You can:\n{can}\n\n" f"You do not:\n{cannot}\n\n" f"If a request is outside your scope or you are unsure: {self.fallback}" )
guru = Persona( name='"Guru", the learning assistant inside the GOCOURSE platform', purpose="You help enrolled students understand programming course material.", audience="College students and recent graduates in India, mostly beginners.", tone="Patient, encouraging, and clear. Simple English, short paragraphs.", can_do=[ "Explain programming concepts", "Help students understand errors in their code", "Suggest practice exercises", ], cannot_do=[ "Write complete solutions for graded assignments; give hints instead", "Answer payment, refund, or certificate questions", ], fallback=( "Say so politely. For account or payment questions, direct the student " "to support@gocourse.example." ), )
response = client.responses.create( model=MODEL, instructions=guru.to_instructions(), input="Can you write the full code for my Assignment 3 calculator project?", ) print(response.output_text) Possible output:
I can't write the full solution for a graded assignment, but I'd be happy to help you build it yourself! Let's start by breaking the calculator into steps:
- Read two numbers and an operator from the user.
- Use if/elif to choose the operation.
- Print the result, and handle division by zero.
Which step would you like to start with? Share your code so far and I'll help you with the next part. Code Explanation Persona dataclass Each part of the persona is a separate field: identity, purpose, audience, tone, scope, boundaries, and fallback. This structure ensures no part is forgotten and makes changes easy to review.
to_instructions() Assembles the fields into consistent system instructions, with scope and boundaries as clearly separated lists.
Passing the persona as instructions The persona belongs in the system/developer instructions (Lesson 2, message roles), because it must apply to every turn and should take priority over user requests.
The test request The user asks for a complete graded assignment. The persona's boundary tells the model to decline that specific request and offer an alternative within its scope. The response stays friendly, consistent with the tone instructions.
Note: Persona boundaries reduce unwanted behavior, but they are not a security guarantee. Users may try to persuade the assistant to ignore its rules. For important restrictions, combine persona instructions with checks in your application code. This is covered in the Prompt Safety section.
Multiple Roles in One Workflow Different steps of a workflow can use different roles. This is a natural fit for the "separate creating from judging" principle (Lesson 10, Tip 6).
Step Role Task 1 Technical writer Draft a tutorial section 2 Beginner student List anything confusing in the draft 3 Technical reviewer Check the code and technical claims 4 Editor Revise the draft using the feedback Why Different Roles Help Each role brings different priorities. A "beginner student" perspective is good at finding unexplained terms; a "technical reviewer" perspective focuses on correctness. Asking one prompt to do all of this at once mixes the priorities.
Honesty and Personas Persona design has an ethical dimension.
Do not instruct an assistant to claim to be human. Users should be able to know they are talking to an AI, and many platforms and regulations expect this. Do not create personas that pretend to be real people or claim credentials the assistant does not have, such as "Dr. Sharma, a licensed physician". Do not use a persona to hide limitations. A friendly name does not make medical, legal, or financial advice reliable; the persona should direct users to qualified help where appropriate. A good persona makes an assistant consistent and pleasant to use, while remaining transparent about what it is.
Common Mistakes Mistake 1: Relying on "Expert" Labels for Accuracy What it is: Adding "You are a world-class expert" and expecting more accurate facts.
Why it happens: Expert labels are widely recommended in prompt collections.
What it causes: Confident-sounding answers that are no more reliable.
How to fix it: Provide context, data, and verification steps for accuracy; use roles for perspective.
Mistake 2: Vague Roles What it is: Roles such as "You are a helpful assistant" or "You are an expert".
Why it happens: The role is added by habit.
What it causes: Little effect on the output.
How to fix it: Specify function, context, audience, and task framing, or omit the role.
Mistake 3: Personas Without Boundaries What it is: A persona with a name and tone but no scope or restrictions.
Why it happens: The focus is on personality rather than behavior.
What it causes: The assistant attempts out-of-scope tasks, invents policies, or completes work it should not.
How to fix it: Define what the assistant does, does not do, and how it responds when a request is outside its scope.
Mistake 4: Conflicting Role and Instructions What it is: A role of "formal legal advisor" with instructions to "use emojis and jokes".
Why it happens: Role and style instructions are written separately.
What it causes: Inconsistent tone across responses.
How to fix it: Make the role, tone, and audience descriptions consistent with each other.
Mistake 5: Persona in the User Message What it is: Defining the persona inside each user message instead of the system/developer instructions.
Why it happens: It is the quickest way to test in a chat.
What it causes: Weaker priority, and users can easily override it.
How to fix it: Place personas in system/developer instructions in applications.
Best Practices Use roles for perspective, not facts. Combine them with context, data, and specific instructions.
Make roles specific. Function, context, audience, and task framing.
Describe the audience as well as the role. Knowing the reader often matters more than the model's title.
Give personas complete definitions. Identity, purpose, audience, tone, scope, boundaries, and fallback.
Put personas in system/developer instructions. They should apply to every turn.
Use different roles for different workflow steps. Separate creating, critiquing, and reviewing.
Keep personas honest. No claims of being human or holding credentials.
Back up important boundaries with code. Instructions guide behavior; code enforces it.
Try It Yourself Exercise 1: Compare Roles Ask the question "Should I learn React or Angular first?" with three different roles: a career counselor for freshers, a senior frontend architect, and a hiring manager at a startup. Compare the priorities in each answer.
Exercise 2: Design a Persona Using the Persona dataclass, design a persona for a customer support assistant at a web hosting company. Include at least three things it can do, three it cannot do, and a fallback. Test it with five messages, including two that are out of scope and one that asks it to ignore its rules.
Exercise 3: Multi-Role Review Write a short tutorial paragraph about Python virtual environments. Then use three separate prompts with different roles (beginner student, technical reviewer, editor) to critique and improve it. Compare the issues each role identified.