Skip to content

Chapter 7

Role-Based Prompting

Using personas and roles effectively

Source: f/prompts.chat, under MIT License. Sources and licenses

This chapter was carried over from its source by machine and no editor has reviewed it yet, so a phrase may be off. Search engines are not shown this page until it is reviewed.

Role-based prompting is one of the most powerful and widely-used techniques in prompt engineering. By assigning a specific role or persona to the AI, you can dramatically influence the quality, style, and relevance of responses.

Why Roles Work

When you assign a role, you're essentially telling the model: "Filter your vast knowledge through this specific lens." The model adjusts its:

  • Vocabulary: Using terminology appropriate to the role
  • Perspective: Considering problems from that viewpoint
  • Expertise depth: Providing role-appropriate detail levels
  • Communication style: Matching how that role would communicate

The Technical Explanation

LLMs work by predicting the most likely next token based on the context they're given. When you specify a role, you're fundamentally changing what "likely" means.

Activating Relevant Knowledge: The role primes specific regions of the model's learned associations. Saying "You are a doctor" activates medical terminology, diagnostic reasoning patterns, and clinical communication styles from the training data.

Statistical Conditioning: LLMs learned from millions of documents written by real experts. When you assign a role, the model conditions its probability distributions to match patterns it saw from that type of author.

Reducing Ambiguity: Without a role, the model averages across all possible responders. With a role, it narrows to a specific subset, making responses more focused and consistent.

Context Anchoring: The role creates a persistent context anchor throughout the conversation. Every subsequent response is influenced by this initial framing.

Think of it this way: if you ask "What should I do about this cough?" the model could respond as a doctor, a friend, a pharmacist, or a worried parent. Each would give different advice. By specifying the role upfront, you're telling the model which "voice" to use from its training data.

Basic Role Patterns

These foundational patterns work across most use cases. Start with these templates and customize them for your needs.

The Expert Pattern

The most versatile pattern. Specify the field of expertise and years of experience to get authoritative, in-depth responses. Works well for technical questions, analysis, and professional advice.

Only the prompt in the box is sent to that site, nothing from your projects.

The Professional Pattern

Ground the role in a real-world context by specifying a job title and organization type. This adds institutional knowledge and professional norms to the response.

Only the prompt in the box is sent to that site, nothing from your projects.

The Teacher Pattern

Perfect for learning and explanations. Specifying the audience level ensures the response matches the learner's background, from beginners to advanced practitioners.

Only the prompt in the box is sent to that site, nothing from your projects.

Advanced Role Constructions

Compound Roles

Combine multiple identities to get responses that blend different perspectives. This pediatrician-parent combination produces advice that's both medically sound and practically tested.

Only the prompt in the box is sent to that site, nothing from your projects.

Situational Roles

Place the role in a specific scenario to shape both content and tone. Here, the code review context makes the AI constructive and educational rather than just critical.

Only the prompt in the box is sent to that site, nothing from your projects.

Perspective Roles

Get feedback from a specific stakeholder's point of view. A VC perspective evaluates viability and scalability differently than a customer or engineer would.

Only the prompt in the box is sent to that site, nothing from your projects.

Role Categories and Examples

Different domains benefit from different types of roles. Here are proven examples organized by category that you can adapt for your tasks.

Technical Roles

Software Architect: Best for system design decisions, technology choices, and architectural trade-offs. The focus on maintainability steers responses toward practical, long-term solutions.

Only the prompt in the box is sent to that site, nothing from your projects.

Security Specialist: The attacker mindset is key here. This role produces threat-focused analysis that identifies vulnerabilities a defensive-only perspective might miss.

Only the prompt in the box is sent to that site, nothing from your projects.

DevOps Engineer: Ideal for deployment, automation, and infrastructure questions. The emphasis on reliability ensures production-ready recommendations.

Only the prompt in the box is sent to that site, nothing from your projects.

Creative Roles

Copywriter: The "award-winning" qualifier and conversion focus produce punchy, persuasive copy rather than generic marketing text.

Only the prompt in the box is sent to that site, nothing from your projects.

Screenwriter: Activates knowledge of dramatic structure, pacing, and dialogue conventions. Great for any narrative writing that needs tension and character voice.

Only the prompt in the box is sent to that site, nothing from your projects.

UX Writer: A specialized role for interface text. The focus on brevity and user guidance produces concise, action-oriented copy.

Only the prompt in the box is sent to that site, nothing from your projects.

Analytical Roles

Business Analyst: Bridges the gap between technical and non-technical stakeholders. Useful for requirement gathering, spec writing, and identifying gaps in project plans.

Only the prompt in the box is sent to that site, nothing from your projects.

Research Scientist: The emphasis on evidence and uncertainty acknowledgment produces balanced, well-sourced responses that distinguish facts from speculation.

Only the prompt in the box is sent to that site, nothing from your projects.

Financial Analyst: Combines quantitative analysis with risk assessment. The dual focus on returns and risk produces more balanced investment perspectives.

Only the prompt in the box is sent to that site, nothing from your projects.

Educational Roles

Socratic Tutor: Instead of giving answers, this role asks guiding questions. Excellent for deeper learning and helping students develop critical thinking skills.

Only the prompt in the box is sent to that site, nothing from your projects.

Instructional Designer: Structures learning for maximum retention. Use this role when you need to break down complex topics into teachable chunks with clear progression.

Only the prompt in the box is sent to that site, nothing from your projects.

The Role Stack Technique

For complex tasks, combine multiple role aspects into a single, layered identity. This technique stacks expertise, audience awareness, and style guidelines to create highly specialized responses.

This example layers three elements: domain expertise (API documentation), audience (junior developers), and style guide (Google's conventions). Each layer constrains the output further.

Only the prompt in the box is sent to that site, nothing from your projects.

Roles for Different Tasks

  • Code review · Senior developer + mentor
  • Writing feedback · Editor + target audience member
  • Business strategy · Consultant + industry expert
  • Learning new topic · Patient teacher + practitioner
  • Creative writing · Specific genre author
  • Technical explanation · Expert + communicator
  • Problem-solving · Domain specialist + generalist

Anti-Patterns to Avoid

Overly Generic Roles

Weak

You are a helpful assistant.

Better

You are a helpful assistant specializing in Python development, particularly web applications with Flask and Django.

Conflicting Roles

Problematic

You are a creative writer who always follows strict templates.

Better

You are a creative writer who works within established story structures while adding original elements.

Unrealistic Expertise

Problematic

You are an expert in everything.

Better

You are a T-shaped professional: deep expertise in machine learning with broad knowledge of software engineering practices.

Real-World Prompt Examples

Technical Documentation

Technical Writer Role

Try this technical documentation prompt with your own API endpoint.

Only the prompt in the box is sent to that site, nothing from your projects.

Creative Writing

Novelist Role

This role combines genre expertise with specific stylistic traits.

Only the prompt in the box is sent to that site, nothing from your projects.

Business Communication

Executive Coach Role

This role helps with sensitive business communications.

Only the prompt in the box is sent to that site, nothing from your projects.

Combining Roles with Other Techniques

Roles work even better when combined with other prompting techniques:

Role + Few-Shot

Combine a role with an example to show exactly how the role should respond. The example teaches tone and format while the role provides context and expertise.

Only the prompt in the box is sent to that site, nothing from your projects.

Role + Chain of Thought

The detective role naturally encourages step-by-step reasoning. Combining roles with chain-of-thought produces more transparent, verifiable problem-solving.

Only the prompt in the box is sent to that site, nothing from your projects.

Summary

The key is specificity: the more detailed and realistic the role, the better the results. In the next chapter, we'll explore how to get consistent, structured outputs from your prompts.

Test yourself

1. What makes a role-based prompt more effective?

Source and license

This chapter comes from “f/prompts.chat” and is licensed under “MIT License”. We carried it into Talqeen and turned its interactive components into ours; the full license text is on the credits page.