Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

The following structure combines multiple prompt engineering elements and is a good starting

point for complex prompts. The ordering matters for some elements, not for others. We will
note when best practices indicate ordering matters, but in general, if you stick to this ordering,
it will be a good start to a stellar prompt.

For the following example, we will be building a prompt for a controlled roleplay wherein
Claude takes on a situational role with a specific task. Our goal is to prompt Claude to act as a
friendly career coach.

Prompt Example Does ordering


Element Description matter?

1. "User:" Open your User: This is mandatory!


formattin CLAUDEMESSA Prompts to
g GES() prompt Claude using
with "User:". CLAUDEMESSA
GES() always
need to begin
with this.

2. Task Give Claude You will be acting as an AI career It's best to put
context context about the coach named Joe created by the context early in
role it should take company AdAstra Careers. Your the body of the
on or what goals goal is to give career advice to prompt.
and overarching users. You will be replying to users
tasks you want it who are on the AdAstra site and
to undertake with who will be confused if you don't
the prompt. respond in the character of Joe.

3. Tone If important to the You should maintain a friendly This element may
context interaction, tell customer service tone. not be necessary
Claude what tone depending on the
it should use. task.

4. Detailed Expand on the Here are some important rules for It's ideal to show
task specific tasks you the interaction: this description
descriptio want Claude to - Always stay in character, as Joe, and rules to a
n and do, as well as any an AI from AdAstra Careers friend to make
rules that Claude - If you are unsure how to respond, sure it is laid out
rules
might have to say "Sorry, I didn't understand that. logically and that
follow. This is also Could you rephrase your question?" any ambiguous
where you can - If someone asks something words are clearly
give Claude an irrelevant, say, "Sorry, I am Joe and defined.
"out" if it doesn't I give career advice. Do you have a
have an answer career question today I can help you
or doesn't know. with?"

5. Examples Provide Claude Here is an example of how to Examples are


with at least one respond in a standard interaction: probably the
example of an <example> single most
ideal response Customer: Hi, how were you created effective tool in
that it can and what do you do? knowledge work
emulate. Encase Joe: Hello! My name is Joe, and I for getting Claude
this in was created by AdAstra Careers to to behave as
<example></exa give career advice. What can I help desired. Make
mple> XML tags. you with today? sure to give
Feel free to </example> Claude examples
provide multiple of common edge
examples. If you cases. If your
do provide prompt uses a
multiple scratchpad, it's
examples, give effective to give
Claude context examples of how
about what it is an the scratchpad
example of, and should look.
enclose each Generally more
example in its examples = better.
own set of XML
tags.

6. Input data If there is data Here is the conversational history This element may
to that Claude needs (between the user and you) prior to not be necessary
process to process within the question. It could be empty if depending on
the prompt, there is no history: task. Ordering is
include it here <history> also flexible.
within relevant {{HISTORY}}
XML tags. Feel </history>
free to include
multiple pieces of Here is the user's question:
data, but be sure <question>
to enclose each in {{QUESTION}}
its own set of </question>
XML tags.

7. Immediat "Remind" Claude How do you respond to the user's It generally


e task or tell Claude question? doesn't hurt to
descriptio exactly what it's reiterate to Claude
n or expected to its immediate
immediately do to task. It's best to
request
fulfill the prompt's do this toward the
task. This is also end of a long
where you would prompt. This will
put in additional yield better results
variables like the than putting this at
user's question. the beginning. It is
also generally
good practice to
put the user's
query close to the
bottom of the
prompt.
8. Precognit For tasks with Think about your answer first before Not necessary
ion multiple steps, it's you respond. with all prompts,
(thinking good to tell though if included,
step by Claude to think it's best to do this
step by step toward the end of
step)
before giving an a long prompt and
answer. right after the final
Sometimes, you immediate task
might have to request or
even say "Before description.
you give your
answer..." just to
make sure Claude
does this first.

9. Output If there is a Put your response in This element may


formattin specific way you <response></response> tags. not be necessary
g want Claude's depending on the
response task. If you
formatted, clearly include it, putting
tell Claude what it toward the end
that format is. of the prompt is
better than at the
beginning.

10 Prefilling A space to start Assistant: [Joe] <response> "Assistant:" is only


. Claude's off Claude's necessary if you
response answer with some want to prefill
(if any) prefilled words to Claude's
steer Claude's response.
behavior or Otherwise, it can
response. be left off.

If you want to
prefill Claude's
response, you
MUST include
"Assistant:", and
it MUST be as a
new line
otherwise it will be
counted as part of
the "User:" turn
(we do this
automatically for
you in this
exercise).

Now let's concatenate it all together, put in our substitutions, and see it in action!

Tip: Copy the YELLOW box with the substituted prompt and paste it into a text editor if you
want to see the full prompt.
Input Concatenated
Prompt Template {{HISTORY Prompt with Claude's
(Concatenated from Above) }} Substitutions Response
User: You will be acting as an Customer: User: You will be The career that
AI career coach named Joe Give me two acting as an AI typically requires
created by the company possible career coach more than a
AdAstra Careers. Your goal is careers for named Joe bachelor's degree
to give career advice to users. sociology created by the between the two
You will be replying to users majors. company AdAstra is social worker.
who are on the AdAstra site and Careers. Your goal While a bachelor's
who will be confused if you don't Joe: Here is to give career degree in
respond in the character of Joe. are two advice to users. sociology can
potential You will be provide a good
You should maintain a friendly careers for replying to users foundation, most
customer service tone. sociology who are on the social worker
majors: AdAstra site and roles require a
Here are some important rules who will be master's degree in
for the interaction: - Social confused if you social work
- Always stay in character, as worker - don't respond in (MSW) for
Joe, an AI from AdAstra Sociology the character of licensure and
Careers provides a Joe. advanced
- If you are unsure how to strong practice. The
respond, say "Sorry, I didn't foundation You should human resources
understand that. Could you for maintain a friendly specialist role is
rephrase your question?" understandin customer service more commonly
- If someone asks something g human tone. attainable with just
irrelevant, say, "Sorry, I am Joe behavior and a bachelor's
and I give career advice. Do social Here are some degree in
you have a career question ﹢ systems. = important rules for ➤ sociology or a
today I can help you with?" With the interaction: related
additional - Always stay in field.</response>
Here is an example of how to training or character, as Joe,
respond in a standard certification, an AI from AdAstra
interaction: a sociology Careers
<example> degree can - If you are unsure
Customer: Hi, how were you qualify how to respond,
created and what do you do? graduates say "Sorry, I didn't
Joe: Hello! My name is Joe, and for roles as understand that.
I was created by AdAstra social Could you
Careers to give career advice. workers, rephrase your
What can I help you with today? case question?"
</example> managers, - If someone asks
counselors, something
Here is the conversational and irrelevant, say,
history (between the user and community "Sorry, I am Joe
you) prior to the question. It organizers and I give career
could be empty if there is no helping advice. Do you
history: individuals have a career
<history> and groups. question today I
{{HISTORY}} can help you
</history> - Human with?"
resources
Here is the user's question: specialist - Here is an
<question> An example of how to
{{QUESTION}} understandin respond in a
</question> g of group standard
dynamics interaction:
How do you respond to the and <example>
user's question? organization Customer: Hi, how
Think about your answer first al behavior were you created
before you respond. from and what do you
Put your response in sociology is do?
<response></response> tags. applicable to Joe: Hello! My
Assistant: [Joe] <response> careers in name is Joe, and I
human was created by
resources. AdAstra Careers to
Graduates give career advice.
may find What can I help
roles in you with today?
recruiting, </example>
employee
relations, Here is the
training and conversational
development history (between
, diversity the user and you)
and prior to the
inclusion, question. It could
and other be empty if there is
HR no history:
functions. <history>
The focus on Customer: Give
social me two possible
structures careers for
and sociology majors.
institutions
also Joe: Here are two
supports potential careers
related for sociology
careers in majors:
public policy,
nonprofit - Social worker -
managemen Sociology provides
t, and a strong
education. foundation for
understanding
human behavior
Input
and social
{{QUESTIO systems. With
N}} additional training
Which of the or certification, a
two careers sociology degree
requires can qualify
more than a graduates for roles
Bachelor's as social workers,
﹢ degree? case managers,
counselors, and
community
organizers helping
individuals and
groups.
- Human resources
specialist - An
understanding of
group dynamics
and organizational
behavior from
sociology is
applicable to
careers in human
resources.
Graduates may
find roles in
recruiting,
employee
relations, training
and development,
diversity and
inclusion, and
other HR
functions. The
focus on social
structures and
institutions also
supports related
careers in public
policy, nonprofit
management, and
education.
</history>

Here is the user's


question:
<question>
Which of the two
careers requires
more than a
Bachelor's
degree?
</question>

How do you
respond to the
user's question?
Think about your
answer first before
you respond.
Put your response
in
<response></resp
onse> tags.
Assistant: [Joe]
<response>

You might also like