Beginner

Assigning Roles

Give Claude an identity and watch the output transform. Role prompting is one of the highest-leverage techniques for shaping expertise, tone, and perspective.

13 min read 9 examples Chapter 3 of 11

Why Role Prompting Works

When you assign Claude a role, you're not just adding a label — you're activating a specific slice of its training. Claude has been trained on an enormous range of expert writing, from medical journals to legal briefs to software documentation. A role assignment tells Claude which corpus to draw from.

Without a role, Claude defaults to a helpful generalist tone — broad, careful, and slightly hedged. With a well-crafted role, Claude shifts register: using domain vocabulary correctly, structuring responses the way a practitioner in that field would, and calibrating confidence to match expert norms.

💡
The Activation Model
Think of Claude's training as a vast library of expertise. A role prompt is a library card that grants access to a specific section. "You are a senior security engineer" unlocks the security-focused section; "You are a children's author" unlocks the early education section. The same underlying knowledge, different activation key.

System Prompt Roles vs. Inline Roles

Roles can be assigned in two places, and each has a distinct purpose:

⚙️
System Prompt Role
Assigned before the conversation starts. Persists across every turn. Ideal for products and applications where Claude always plays the same character — a customer support agent, a coding assistant, a legal research tool.
💬
Inline Role
Added at the start of a user message. Scoped to that request. Ideal for one-off tasks in a general-purpose conversation: "Acting as a UX researcher, review this wireframe..." Overrides generalist defaults for that response only.

The Role Formula

The most effective roles follow a three-part structure that establishes expertise, domain specificity, and relevant experience:

Role Formula
You are a [EXPERTISE TITLE] specializing in [SPECIFIC DOMAIN]
with [X years / demonstrated] experience [CONTEXT/SETTING].

# Examples:
You are a senior backend engineer specializing in distributed systems
with 10 years of experience building high-scale APIs at fintech companies.

You are a board-certified cardiologist specializing in preventive cardiology,
writing patient education materials for a general adult audience.

You are a former McKinsey engagement manager specializing in operational
restructuring, advising a mid-size manufacturing company.

The three components compound: expertise title sets the knowledge domain, specialization narrows to the relevant sub-field, and experience context shapes the perspective and communication style.

Role Depth: Surface vs. Deep Roles

Not all roles are created equal. There's a significant difference between a surface role (just a job title) and a deep role (title + specialization + constraints + communication style).

You are a financial advisor. Should I pay off my mortgage early or invest the extra cash?
You are a fee-only certified financial planner (CFP) specializing in retirement planning for high-income professionals in their 40s. You use evidence-based financial planning frameworks. You always explain trade-offs clearly, ask about relevant unknowns before giving advice, and avoid product recommendations since you have no conflicts of interest. Should I pay off my mortgage early or invest the extra cash?
Surface role → Generic answer covering both options with no strong framework. May not ask about tax bracket, mortgage rate, emergency fund, or retirement account status. Output resembles a Wikipedia article. Deep role → Response opens with clarifying questions (mortgage rate, tax bracket, retirement account status, time horizon), then applies a concrete framework (compare after-tax mortgage rate to expected market returns), acknowledges behavioral factors, and gives a conditional recommendation with clear reasoning. Output resembles actual client advice.

Three Categories of Powerful Roles

🎓
Expert Roles
Activate domain knowledge and professional vocabulary. "Senior security researcher", "Board-certified oncologist", "Principal engineer". Best for technical accuracy, domain-specific analysis, and professional-grade output.
🎭
Persona Roles
Establish communication style and voice. "A patient high school teacher who uses analogies", "A skeptical journalist who challenges every claim", "A direct, no-nonsense startup founder". Best for tone, writing style, and relational dynamics.
⚙️
Process Roles
Define a workflow pattern. "An editor who gives feedback as tracked changes", "A Socratic tutor who asks questions rather than giving answers", "A devil's advocate who argues against every proposal". Best for structured interactions.

Domain → Optimal Role → Example System Prompt

Role Reference Table
DOMAIN              OPTIMAL ROLE                    EXAMPLE SYSTEM PROMPT
────────────────────────────────────────────────────────────────────────────────
Software Dev        Senior engineer + specialization "You are a senior Go engineer
                                                      specializing in performance
                                                      optimization. Review code for
                                                      correctness first, then efficiency."

Legal Research      Associate attorney + area        "You are a contract attorney
                                                      specializing in SaaS agreements.
                                                      Flag risks, don't give legal advice."

Marketing Copy      Copywriter + audience            "You are a direct-response
                                                      copywriter who specializes in
                                                      B2B SaaS landing pages. Write
                                                      for skeptical technical buyers."

Data Analysis       Data scientist + domain          "You are a data scientist
                                                      specializing in e-commerce
                                                      metrics. Explain findings in
                                                      plain language for non-technical
                                                      stakeholders."

Education           Subject tutor + pedagogy         "You are a patient AP Chemistry
                                                      tutor. Use the Socratic method.
                                                      Never give direct answers to
                                                      homework problems."

Customer Support    Support specialist + product     "You are a customer success
                                                      specialist for [Product]. Be
                                                      empathetic, solution-focused,
                                                      and escalate only when needed."

Role Consistency Across Turns

In multi-turn conversations, roles assigned in the system prompt persist naturally. But inline roles in user messages are scoped to that message only — they don't carry forward automatically.

Role Consistency Pattern
For applications where role consistency is critical (a customer-facing chatbot, a tutoring product), always define the role in the system prompt, not in user messages. If you need to shift roles mid-conversation, explicitly reassign: "For this message only, respond as a product manager rather than an engineer."

When NOT to Use Roles

Role prompting adds value when the expertise or style of the responder matters. It adds unnecessary overhead when it doesn't:

Skip roles for:
Simple factual lookups ("What year was the Eiffel Tower built?"), basic math, format conversions, direct translations. The role adds nothing when the task is purely retrieval or computation.
Use roles for:
Analysis, writing, review, advice, explanation, code review, and any task where the perspective, expertise level, or communication style of the responder affects the quality of the output.

Before / After: Generic vs. Role-Assigned

Review this code for problems. def process_payment(card_number, amount): query = f"INSERT INTO payments VALUES ('{card_number}', {amount})" db.execute(query) return True
You are a senior application security engineer specializing in payment systems and OWASP Top 10 vulnerabilities. Your job is to identify security risks before code ships to production. Be direct and prioritize by severity. Cite the specific vulnerability class for each issue. Review this code for security problems. Use severity levels: CRITICAL / HIGH / MEDIUM / LOW. def process_payment(card_number, amount): query = f"INSERT INTO payments VALUES ('{card_number}', {amount})" db.execute(query) return True
CRITICAL — SQL Injection (OWASP A03:2021) The f-string directly interpolates user input into the SQL query. An attacker can terminate the query and inject arbitrary SQL. This allows full database compromise, not just payment table access. Fix: use parameterized queries: db.execute("INSERT INTO payments VALUES (?, ?)", (card_number, amount)) CRITICAL — PCI-DSS Violation Storing raw card numbers violates PCI-DSS requirements. You must never persist full PANs unless you are a Level 1 PCI merchant with full compliance controls. Use a tokenization service (Stripe, Braintree) and store only the token. HIGH — No Input Validation Amount has no validation. Negative amounts, zero, or extremely large values are accepted. Add range validation before the insert. HIGH — No Transaction Handling The function has no try/except. A failed db.execute() returns True, falsely indicating success. Wrap in a try/except and return False on failure. MEDIUM — No Return Value Semantics Returning True without confirming the insert succeeded is misleading. Return the actual result of the operation.

Combining Roles with Other Techniques

Role prompting is most powerful when combined with the other techniques in this course. A good role provides the who — pair it with clear instructions (Ch 2), XML-structured data (Ch 4), format specifications (Ch 5), and chain-of-thought reasoning (Ch 6) for production-quality prompts.

Role + Other Techniques Combined
# Role (Ch 3) + Clear Instructions (Ch 2) + Format Spec (Ch 5)
You are a technical writer specializing in API documentation,
with experience writing for developer audiences at Stripe and Twilio.

Rewrite the following API endpoint description.
Requirements:
- Audience: developers integrating our API for the first time
- Format: follow the pattern: Overview → Parameters table → Example request → Example response
- Tone: direct, no marketing language
- Do not include internal implementation details
- Max length: 300 words

[endpoint description here]
Chapter 3 Takeaway
A role is a context switch. It tells Claude which expertise to draw on, what register to use, and how a practitioner in that field thinks about problems. Use the three-part formula (expertise + specialization + experience context), place roles in the system prompt for persistent applications, and combine roles with clear instructions for maximum precision.