Prompt Engineering Step 3: Role-Playing Prompts (Copilot)

Assigning a role or persona to GitHub Copilot Chat at the beginning of your prompt can influence the tone, style, and focus of its responses.

Why Use Role-Playing?

  • Targeted Explanations: Request explanations tailored to different levels of expertise.
  • Perspective-Based Feedback: Ask for code reviews or suggestions from a specific viewpoint (e.g., performance, security, maintainability).
  • Style Emulation: Encourage Copilot to generate code or documentation matching a particular style associated with a role.

How to Use Role-Playing in Prompts

Start your prompt in Copilot Chat by clearly defining the role. Combine this with specific commands or context as needed.

Examples (Use in Chat View / Inline Chat):

  • Senior Developer Review:
    Act as a principal software engineer specializing in C#. Review the code in #selection. Focus on potential race conditions, exception handling best practices, and opportunities for using modern .NET asynchronous patterns.
  • Beginner Explanation:
    Explain dependency injection in ASP.NET Core like I'm a junior developer who has only worked with static classes before.
  • QA Perspective:
    Assume the role of a QA engineer. Based on the function in #selection, suggest 5 edge case scenarios that should be tested using the /tests command.
  • Database Admin Optimization:
    You are a SQL Server DBA. Analyze the following query in #selection and suggest optimizations for better performance on large tables. /explain
Experiment!

Try assigning different roles relevant to your task (e.g., "Accessibility Expert", "Technical Writer", "DevOps Engineer") to guide Copilot's output effectively.