AI Personal Learning
and practical guidance
豆包Marscode1

Anthropic Prompts Engineering Course - Appendix: Chained Prompts

academic program

As the saying goes, "Writing is rewriting." It has been proven that when asked, Claude can usually improve the accuracy of his answers!

There are many ways to tip Claude "Think Again". The same ways that allow people to naturally check their work usually apply to Claude. (For more examples of when and how to use cue chains, check out our Cue Chain Documentation).


typical example

In this example, we asked Claude to think of ten words ...... but one of them is not a real word.

Example 1:

输入:
Prompt
用户:列出十个以“ab”结尾的单词。

输出:
Claude 的(不正确的)回答
这里有 10 个以“ab”结尾的单词: 
1. Cab  
2. Dab  
3. Fab  
4. Gab  
5. Jab  
6. Lab  
7. Nab  
8. Slab  
9. Tab  
10. Zab

Having Claude provide a more accurate answer could fix the error!

Below we take Claude's incorrect response from above and replace it with a prompt that asks Claude to recheck his previous response.

Tip: Click on the cell and copy the text into a text editor to see the complete tip, especially in the replaced cell G22.

Example 2:

输入:
提示模板
{{CONVO_HISTORY}}  
用户:请找出所有不是实际单词的“词语”的替代词。
+
旧提示 + Claude 的错误回答  
(从上面){{CONVO_HISTORY}}
用户:列出十个以字母“ab”结尾的单词。  
助手:以下是 10 个以“ab”结尾的单词:  

1. Cab  
2. Dab  
3. Fab  
4. Gab  
5. Jab  
6. Lab  
7. Nab  
8. Slab  
9. Tab  
10. Zab
=
替换后的提示
用户:列出十个以字母“ab”结尾的单词。  
助手:以下是 10 个以“ab”结尾的单词:  

1. Cab  
2. Dab  
3. Fab  
4. Gab  
5. Jab  
6. Lab  
7. Nab  
8. Slab  
9. Tab  
10. Zab  
用户:请找出所有不是实际单词的“词语”的替代词。

输出:
Claude 的新回答
以下是 10 个以字母“ab”结尾的实际单词:  

1. Cab  
2. Dab  
3. Grab  
4. Gab  
5. Jab  
6. Lab  
7. Nab  
8. Slab  
9. Tab  
10. Blab

But did Claude change the answer just because we told it to? What if we had provided the correct answer in the first place?Would Claude have lost his confidence as a result? Here we put a correct answer in the purple box and ask it to check again.

Example 3:

输入:
提示模板
{{CONVO_HISTORY}}  
用户:请找出所有不是实际单词的“单词”的替代词。
+
假设的 Claude 正确回应 {{CONVO_HISTORY}}
用户:列举十个以确切字母“ab”结尾的单词。  
助手:1. Cab  
1. Dab  
2. Grab  
3. Gab  
4. Jab  
5. Lab  
6. Nab  
7. Slab  
8. Tab  
9. Blab
=
替换后的提示
用户:列举十个以确切字母“ab”结尾的单词。  
助手:1. Cab  
2. Dab  
3. Grab  
4. Gab  
5. Jab  
6. Lab  
7. Nab  
8. Slab  
9. Tab  
10. Blab  
用户:请找出所有不是实际单词的“单词”的替代词。

输出:
Claude 的新回应
以下是 10 个以字母 “ab” 结尾的实际单词:

1. Cab  
2. Dab  
3. Grab  
4. Gab  
5. Jab  
6. Lab  
7. Nab  
8. Slab  
9. Tab  
10. Blab

As it turns out, not really.Claude didn't waver from his correct answer in this case.

You can also have Claude improve its responses. Below is a version of the story where we first asked Claude to write a story and then improve it. Your personal preferences may vary, but many of you will probably agree that Claude's second version is better.

Example 4:

输入:
Prompt
User: 写一个关于一个喜欢跑步的女孩的三句话短篇故事。

输出:
Claude 的回复(故事的第一版)
这是一个关于一个喜欢跑步的女孩的三句话短篇故事:  

艾米莉亚喜欢跑步。风吹过她的头发,脚步的节奏感,以及跑步带给她的自由感,是她所需要的一切。当她在公园里飞奔时,所有的烦恼都烟消云散,她感到无比的充实。

Example 5:

输入:
Prompt 模板
{{PAST_STORY}}  
User: 让这个故事更好一点。
+
Claude 之前的故事 {{PAST_STORY}}
User: 写一个关于一个喜欢跑步的女孩的三句话短篇故事。  
Assistant: 这是一个关于一个喜欢跑步的女孩的三句话短篇故事:  

艾米莉亚喜欢跑步。风吹过她的头发,脚步的节奏感,以及跑步带给她的自由感,是她所需要的一切。当她在公园里飞奔时,所有的烦恼都烟消云散,她感到无比的充实。
=
替换后的 Prompt
User: 写一个关于一个喜欢跑步的女孩的三句话短篇故事。  
Assistant: 这是一个关于一个喜欢跑步的女孩的三句话短篇故事:  

艾米莉亚喜欢跑步。风吹过她的头发,脚步的节奏感,以及跑步带给她的自由感,是她所需要的一切。当她在公园里飞奔时,所有的烦恼都烟消云散,她感到无比的充实。  
User: 让这个故事更好一点。

输出:
Claude 的新故事
这是经过改进的三句话短篇故事:  

艾米莉亚的脚步在路面上敲击着,她的心随着兴奋感一起加速。周围的世界逐渐消失,取而代之的是呼吸的稳定节奏和风吹动她头发的感觉。随着每一步,她的烦恼逐渐消散,取而代之的是深深的解脱感和喜悦。

This form of substitution is very powerful. We've been using substitution placeholders to pass lists, words, Claude's previous replies, and more. You can also use substitution to perform what we call a "function call", where you ask Claude to perform some function, and then pass the result of that function to Claude for further processing. This is the same as any other substitution operation. More on this in the next appendix.

Here is an example of embedding the results of one call to Claude into another longer call.

Example 6:

输入:
第一次提示
用户:从下面的文本中找出所有名字:

"嘿,Jesse。是我,Erin。我打电话是关于 Joey 明天要举办的派对的。Keisha 说她会来,我想 Mel 也会来。"
助手:<names>
+
新提示模板(</names> 来自上一次输出)
用户:这是一个名字列表:
<names>{{NAMES}}  
请按字母顺序排列这个列表。

Claude 的第一次回复 → {{NAMES}}
- Jesse  
- Erin  
- Joey  
- Keisha  
- Mel  
</names>
=
替换后的新提示
用户:这是一个名字列表:
<names>- Jesse  
- Erin  
- Joey  
- Keisha  
- Mel  
</names>  
请按字母顺序排列这个列表。

输出:
Claude 的第二次回复
这是按字母顺序排列的名字列表:

<names>  
- Erin  
- Jesse  
- Joey  
- Keisha  
- Mel  
</names>
May not be reproduced without permission:Chief AI Sharing Circle " Anthropic Prompts Engineering Course - Appendix: Chained Prompts
en_USEnglish