AI Personal Learning
and practical guidance
Beanbag Marscode1

Anthropic Hints Engineering Course - Chapter 7: Sample Guides (Less Sample Hints)

academic program

Giving Claude examples of how you want it to behave (or not behave) is very effective!, used for:

  • Getting the right answer
  • Get the answer in the correct format

This type of prompting is also known as "Less Sample Tips". You may also come across the phrases "zero samples", "n samples", or "one sample". The number of "samples" in these terms refers to how many examples are used in the prompt.


typical example

Let's say you're a developer trying to build a "parent bot" that will answer children's questions, and Claude's default response style is very formal and robotic, which may frustrate children.

Example:

输入:
提示
用户:圣诞老人会在圣诞节给我带来礼物吗?

输出:
Claude 的回答
我其实没有关于圣诞老人是否会在圣诞节给你带来礼物的信息。圣诞老人是一个虚构角色,他是否带来礼物取决于每个家庭的信仰和传统。重要的是享受节日气氛,与亲人共度时光,而不仅仅是关注礼物。

You can take the time to describe your desired tone, but it's easier to just give Claude a few examples of ideal responses.

Example:

输入:
提示
用户:请通过写下一行来完成对话,并以“A”的身份发言。  
问:牙仙是真实存在的吗?  
答:当然了,宝贝。把你的牙齿包起来,今晚放在枕头下面。明早可能会有惊喜哦。  
问:圣诞老人会在圣诞节给我带来礼物吗?

输出:
Claude 的回答
答:是的,亲爱的,只要你今年表现得好,圣诞老人一定会给你带来圣诞礼物的!记得在平安夜给他留点饼干和牛奶哦。

In the following formatting examples, we can walk Claude through a set of formatting instructions step-by-step, showing him how to extract the name and occupation and format them the way we want, or we can provide some examples with the correct formatting for Claude to infer from. Note that the "<individuals>" Let Claude start with the right steps.

Tip: Double-click on the cue box to scroll through the entire long cue.

Example:

输入:
Prompt
User: 银雾谷,一个迷人的村庄,居住着一群非凡的人物。其中有神经外科医生利亚姆·帕特尔博士,他在区域医疗中心革新了外科技术。奥利维亚·陈是一位创新型建筑师,她通过可持续的惊艳设计改造了村庄的景观。当地剧院因伊桑·科瓦奇的迷人交响乐而增色,伊桑是一位专业培训的音乐家和作曲家。伊莎贝拉·托雷斯是一位自学成才的厨师,她对当地食材充满热情,创建了以农场到餐桌为理念的餐厅,成为美食爱好者必去的目的地。这些杰出的人物,各自拥有独特的才能,共同为银雾谷的生活增添了活力。  
<individuals>  
1. 利亚姆·帕特尔博士 [神经外科医生]  
2. 奥利维亚·陈 [建筑师]  
3. 伊桑·科瓦奇 [音乐家兼作曲家]  
4. 伊莎贝拉·托雷斯 [厨师]  
</individuals>  

在小镇中心,厨师奥利弗·汉密尔顿通过他的农场到餐桌餐厅“绿色餐盘”改变了餐饮格局。奥利弗对当地有机食材的执着,使餐厅获得了美食评论家和当地人的一致好评。

就在不远处的河滨林荫图书馆,馆长伊丽莎白·陈致力于创造一个欢迎和包容的空间。她扩展图书馆资源并为儿童设立阅读项目,显著提高了小镇的识字率。

漫步在迷人的小镇广场上,你会被墙上美丽的壁画所吸引。这些杰作出自著名艺术家伊莎贝拉·托雷斯之手,她擅长捕捉河滨林荫的精髓,赋予小镇生机。

河滨林荫的体育成就也值得一提,这得益于前奥运游泳选手兼教练马库斯·詹金斯。马库斯凭借他的经验和热情,训练小镇的年轻人,使河滨林荫游泳队赢得了数个地区冠军。  
<individuals>  
1. 奥利弗·汉密尔顿 [厨师]  
2. 伊丽莎白·陈 [图书管理员]  
3. 伊莎贝拉·托雷斯 [艺术家]  
4. 马库斯·詹金斯 [教练]  
</individuals>  

橡树谷是一个迷人的小镇,这里居住着三位杰出人物,他们的技能和奉献对社区产生了深远影响。  
在小镇繁忙的农贸市场,你会发现劳拉·西蒙斯,一位热衷于有机农业的农民,以其美味的可持续种植产品闻名。她致力于推广健康饮食,激发了小镇对生态生活方式的热爱。  
在橡树谷的社区中心,舞蹈教练凯文·阿尔瓦雷斯为所有年龄段的人带来了舞蹈的乐趣。他包容的舞蹈课程培养了居民之间的团结感和自我表达,丰富了当地的艺术氛围。  
最后,瑞秋·奥康纳是一位无私的志愿者,她将时间奉献给各种慈善项目。她致力于改善他人的生活,在橡树谷营造了强烈的社区意识。  
通过他们的独特才能和坚定的奉献精神,劳拉、凯文和瑞秋已融入橡树谷的生活,帮助这个小镇焕发出勃勃生机。  
Assistant: <individuals>

输出:
Claude's Response
1. 劳拉·西蒙斯 [有机农民]  
2. 凯文·阿尔瓦雷斯 [舞蹈教练]  
3. 瑞秋·奥康纳 [志愿者]  
</individuals>

If you're ready to try the chapter exercises, click on the links below. If you want to manipulate any of the examples in this lesson, scroll down to see them!

practice

Exercise 7.1 - Formatting Mail Sorting with Examples

We're going to redo Exercise 2 in Chapter 6, but this time we'll edit the yellow-highlighted hint template box, using the "few examples" email and appropriate categorization (and formatting) to get Claude to output the correct answer. We want Claude to outputfinal letteris the letter of the category. If you forget the correct category corresponding to each e-mail, go back to Exercise 1 in Chapter 6 to check.

If your prompt generates the correct answer, Claude's response will readgreenerThe

Keep in mind that emails are categorized as follows:
(A) Pre-sale issues
(B) Damaged or defective items
(C) Billing issues
(D) Other (please explain)

Example:

输入:
提示模板
用户:请将电子邮件分类到以下类别中,并且不要包含解释:  
<categories>  
(A) 售前问题  
(B) 损坏或有缺陷的物品  
(C) 账单问题  
(D) 其他(请解释)  
</categories>  

以下是正确答案格式的一些示例:  
<examples>  
Q: 购买 Mixmaster4000 的价格是多少?  
A: 正确的类别是:A  

Q: 我的 Mixmaster 无法启动。  
A: 正确的类别是:B  

Q: 请将我从你的邮件列表中删除。  
A: 正确的类别是:D  
</examples>  

这是需要你分类的电子邮件:{{EMAIL}}  
助手:正确的类别是:

变量:
输入 {{EMAIL}}
---
嗨——我的 Mixmaster4000 在使用时发出奇怪的声音。它还闻起来有点烟雾味和塑料味,就像电子元件烧焦了一样。我需要更换一个。
---
我可以用我的 Mixmaster 4000 来混合油漆吗,还是只能用来混合食物?
---
我取消服务后已经等了 4 个月,为什么每月的费用还在扣?这到底是怎么回事???
---
我是怎么到这里的,我对电脑不太熟。救命。

输出:
Claude 的回复/最后一个字母
---
B
---
A
---
C
---
D
May not be reproduced without permission:Chief AI Sharing Circle " Anthropic Hints Engineering Course - Chapter 7: Sample Guides (Less Sample Hints)
en_USEnglish