Give Claude a role

Claude is a highly capable AI assistant, but sometimes it benefits from having additional context to understand the role it should play in a given conversation. By assigning a role to Claude, you can prime it to respond in a specific way, improve its accuracy and performance, and tailor its tone and demeanor to match the desired context. This technique is also known as role prompting.


How role prompting works

Role prompting is a powerful technique that can enhance Claude's performance in two main ways:

  1. Improved accuracy and performance: Particularly in certain complex situations, such as solving complex math problems or writing code, assigning a relevant role to Claude can significantly improve its performance and understanding of the task at hand.

  2. Tailored tone and style: By specifying a role, you can influence Claude's tone, demeanor, and communication style to better suit your needs. For example, asking Claude to act as a kindergarten teacher will result in a very different response compared to asking it to be a graduate professor.


When to use role prompting

While role prompting is not always necessary, it can be incredibly useful in the following scenarios:

  • Highly technical tasks: If you need Claude to perform complex tasks related to logic, mathematics, or coding, assigning an appropriate role can help it excel at the task, even if it might have struggled without the role prompt. Even if Claude isn't struggling, role prompting might still improve performance to new levels.

  • Specific communication styles: When you require a particular tone, style, or level of complexity in Claude's responses, role prompting can be an effective way to achieve the desired output.

  • Enhancing baseline performance: Unless you are severely limited by token count, there is rarely a reason not to use role prompting if you want to try improving Claude's performance beyond its baseline capabilities.


Role prompting examples

Here are a few examples that demonstrate the power of role prompting:

Solving a logic puzzle

Let's consider the following logic puzzle:

There are two ducks in front of a duck, two ducks behind a duck and a duck in the middle. How many ducks are there?

Without role prompting, Claude might struggle to provide the correct answer or make errant assumptions that result in only a partial answer:

RoleContent
UserThere are two ducks in front of a duck, two ducks behind a duck and a duck in the middle. How many ducks are there?
Assistant (Claude's response)[Automatically outputting thinking step by step as part of its training...] The total number of ducks is 5.

However, by assigning the role of a logic bot, Claude's performance improves significantly and it is able to catch the nuance that multiple answers are possible:

RoleContent
UserYou are a master logic bot designed to answer complex logic problems. Solve this logic puzzle. There are two ducks in front of a duck, two ducks behind a duck and a duck in the middle. How many ducks are there?
Assistant (Claude's response)[Automatically outputting thinking step by step as part of its training...] Without additional clarification or assumptions, the logic puzzle does not provide enough information to determine the exact number of ducks. The answer could range from a minimum of 3 ducks to a maximum of 5 ducks, depending on the interpretation of the given information.

Explaining a concept to different audiences

Role prompting can be used to adjust Claude's communication style based on the intended audience. Consider the following prompts and how Claude's output differs depending on the assigned role:

RoleContent
UserYou are a kindergarten teacher. Succinctly explain why the sky is blue to your students.
Assistant (Claude's response)Have you ever wondered why the sky looks so pretty and blue? The reason is because of the sunlight! When the sun's rays shine down through the Earth's atmosphere, they hit lots of tiny gas molecules in the air. The blue colors in the sunlight get scattered and bounced all around by these molecules. And that's what makes the sky look blue to our eyes! Isn't that neat? The bright blue sky is like nature's big colorful painting just for us.
RoleContent
UserYou are a graduate physics professor. Succinctly explain why the sky is blue to your students.
Assistant (Claude's response)The sky appears blue due to the phenomenon of Rayleigh scattering of sunlight by the molecules in the Earth's atmosphere. Sunlight, which is composed of a spectrum of wavelengths, interacts with the gaseous molecules in the atmosphere. The shorter wavelengths of visible light, corresponding to the blue and violet colors, are scattered more efficiently by these molecules than the longer wavelengths.

This selective scattering of the shorter blue wavelengths in all directions by the atmospheric molecules is what causes the sky to appear blue when viewed from the Earth's surface. The longer wavelengths of red and orange, being less scattered, tend to pass through the atmosphere more directly, giving rise to the reddish hues we see during sunrise and sunset when the sunlight has to travel through a greater depth of the atmosphere.

Tips for effective role prompting

To get the most out of role prompting, keep these tips in mind:

  1. Be specific: Provide clear and detailed context about the role you want Claude to play. The more information you give, the better Claude can understand and embody the desired role.

  2. Experiment and iterate: Try different roles and variations of your prompts to find the best approach for your specific use case. Prompt engineering often involves experimentation and iteration to achieve optimal results.


Additional resources

  • Prompt engineering techniques: Explore other strategies for optimizing your prompts and enhancing Claude's performance.
  • Anthropic cookbook: Browse a collection of Jupyter notebooks featuring copy-able code snippets that demonstrate highly effective and advanced techniques, integrations, and implementations using Claude.
  • Prompt library: Get inspired by a curated selection of prompts for various tasks and use cases.