比较模糊提示与具体提示
通过并列示例展示具体性带来的显著差异
比较模糊提示与具体提示 是 CoddyKit 上的免费 AI Prompt Engineering 课时。 这是第 4 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 AI Prompt Engineering 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 AI Prompt Engineering 课程共包含 4 节课。
并排比较法
掌握提示词质量最快的方法,是并排研究具体的改写,并分析每项改进为何有效。
本课将研究五条模糊提示词及其具体改写。对于每一组,我们会找出所做的确切改动,以及每项改进如何引导模型生成更好的输出。
第 1 组:博客文章
模糊:“撰写一篇关于远程工作的博客文章。”
具体:“为中级软件开发人员撰写一篇 600 字的博客文章,标题为《扼杀我工作效率的 3 个远程工作习惯(以及我现在的做法)》。使用第一人称口吻和对话式语气。结构:1 段简介、3 个带 H2 标题的部分,以及一个引导下载免费模板的 CTA。”
为什么有效:增加了字数、标题(也就确定了切入角度)、受众、口吻、语气、结构和特定的结尾元素。没有任何维度需要靠运气决定。
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=800,
messages=[{
'role': 'user',
'content': (
'Write a 600-word blog post titled '
'"The 3 Remote Work Habits That Killed My Productivity (And What I Do Now)" '
'for an audience of mid-level software developers. '
'First-person voice, conversational tone. '
'Structure: 1-paragraph intro, 3 H2 sections (one per habit), '
'1 closing paragraph with a CTA to download a free productivity template.'
)
}]
)
print(response.content[0].text[:400], '...')第 2 组:代码审查
模糊:“审查我的代码。”
具体:“审查以下 Python 函数。只关注:1)正确性错误;2)未处理的边界情况。请 NOT 评论样式、命名或格式。输出格式:问题的编号列表,每个问题包含:问题描述(1 句话)、受影响的行、建议的修复方案(代码片段)。”
为什么有效:明确了审查范围(正确性和边界情况),明确排除了其他维度(样式和命名),并指定了精确的输出结构,每个问题包含三个字段。
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
code = (
'def get_user(users, user_id):\n'
' for user in users:\n'
' if user["id"] == user_id:\n'
' return user["name"]\n'
' return users[0]["name"]\n'
)
response = client.chat.completions.create(
model='gpt-4o',
messages=[{
'role': 'user',
'content': (
'Review the following Python function.\n'
'Focus ONLY on: 1) correctness bugs, 2) unhandled edge cases.\n'
'Do NOT comment on style, naming conventions, or formatting.\n'
'Output format: numbered list. Each item: issue (1 sentence), '
'affected line, suggested fix as a code snippet.\n\n'
+ code
)
}]
)
print(response.choices[0].message.content)第 3 组:电子邮件主题行
模糊:“为我的新闻简报撰写电子邮件主题行。”
具体:“为面向数据科学家的 Python 周报撰写 10 个电子邮件主题行。每个主题行必须少于 50 个字符,包含一个能提高打开率的吸引点(好奇心缺口、编号列表或令人意外的论断),并避免使用会触发垃圾邮件过滤的词,例如 FREE 或 URGENT。以编号列表输出,并在方括号中标明吸引点类型。”
为什么有效:明确了数量、长度限制、吸引点要求、排除项列表和带标签的输出格式,将模糊的创意任务转化为基于规则的生成任务。
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=400,
messages=[{
'role': 'user',
'content': (
'Write 10 email subject lines for a weekly newsletter '
'about Python tips for data scientists. '
'Requirements:\n'
'- Each under 50 characters\n'
'- Must use one of these hooks: [CURIOSITY GAP], [NUMBER], or [SURPRISING CLAIM]\n'
'- No spam words: FREE, URGENT, ACT NOW, LIMITED TIME\n'
'- Output as numbered list with hook type in brackets at the end of each line'
)
}]
)
print(response.content[0].text)第 4 组:会议总结
模糊:“总结这份会议文字记录。”
具体:“使用以下格式总结这份会议文字记录:1)会议目的(1 句话);2)做出的关键决策(项目符号列表,最多 5 项);3)行动项目(表格,列为:任务、负责人、截止日期);4)待解决问题(编号列表)。如果某个字段缺少信息,请写‘不适用’。不要加入任何观点——只写事实和承诺。”
为什么有效:提供了精确的模板,指定了每个部分的限制,定义了表格结构,为缺失数据设置了备用方案,并增加了语气约束(只写事实)。
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
transcript = (
'John: We need to decide on the launch date. '
'Sarah: I think Q3 works. We need the API done first. '
'John: Agreed. Sarah, can you own the API? '
'Sarah: Yes, I can have it by July 15th. '
'John: Great. Who handles marketing? '
'Mike: I will, but I need the feature list first. '
'John: We still need to confirm pricing — tabled for next week.'
)
response = client.chat.completions.create(
model='gpt-4o',
messages=[{
'role': 'user',
'content': (
'Summarize this meeting transcript in this exact format:\n'
'1. Meeting Purpose: (1 sentence)\n'
'2. Key Decisions: (bullet list, max 5)\n'
'3. Action Items: (markdown table: Task | Owner | Deadline)\n'
'4. Open Questions: (numbered list)\n'
'Missing info: write N/A. Facts only, no opinions.\n\n'
'Transcript:\n' + transcript
)
}]
)
print(response.choices[0].message.content)第 5 组:解释说明
模糊:“解释机器学习。”
具体:“面向一家医疗保健公司的产品经理,用 3 段解释机器学习。该读者了解统计学,但从未编写过代码。第 1 段:说明机器学习是什么,以及它与传统编程有何不同。第 2 段:提供一个真实的医疗保健示例(诊断或药物研发)。第 3 段:说明一个应避免的常见误解。总字数最多 200 字。”
为什么有效:定义了结构(3 段及每段指定的主题)、受众(具体职位、领域和背景)、每段的内容要求以及总体字数限制。
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=350,
messages=[{
'role': 'user',
'content': (
'Explain machine learning in exactly 3 paragraphs. '
'Audience: a product manager at a healthcare company who understands statistics '
'but has never written code.\n'
'Paragraph 1: what ML is and how it differs from traditional programming.\n'
'Paragraph 2: a specific real-world healthcare example (diagnosis or drug discovery).\n'
'Paragraph 3: one common misconception non-technical people have about ML.\n'
'Max 200 words total. No bullet points — flowing prose only.'
)
}]
)
print(response.content[0].text)优秀改写的构成
纵观这五组示例,每个有效的改写都做了同样几件事:
- 替换模糊动词:将“撰写”“审查”“解释”替换为结构化任务
- 指定输出格式:列表、表格,或包含指定内容的段落
- 增加可衡量的约束:字数、项目数和字符数限制
- 明确受众:职位、背景和情境
- 至少增加一条排除规则:明确应省略的内容
# Pattern extractor: identify improvements between two prompts
def analyze_improvement(vague, specific):
improvements = []
words = specific.lower()
if any(str(n) in words for n in range(10, 10000)):
improvements.append('Quantitative constraint added')
if 'do not' in words or 'exclude' in words or 'avoid' in words or 'no ' in words:
improvements.append('Negative constraint added')
if 'audience' in words or 'for a' in words or 'targeting' in words:
improvements.append('Audience specified')
if 'format:' in words or 'table' in words or 'list' in words or 'paragraph' in words:
improvements.append('Output format defined')
if 'example' in words or 'such as' in words or 'like:' in words:
improvements.append('Example provided')
print('Improvements detected:')
for i in improvements:
print(f' + {i}')
vague = 'Write a blog post about remote work.'
specific = 'Write a 600-word blog post for mid-level developers with 3 H2 sections and a closing CTA. No bullet points. Avoid generic productivity advice.'
analyze_improvement(vague, specific)只增加一个维度时会发生什么
只增加一项改进确实有所帮助,但部分具体化仍会留下很大的空白。请比较:
- “撰写一篇关于远程工作的博客文章”——没有任何约束
- “撰写一篇 600 字的关于远程工作的博客文章”——只有长度明确;切入角度、受众和结构仍然模糊
- “为开发人员撰写一篇 600 字的关于远程工作的博客文章,使用对话式语气”——明确了长度、受众和语气;结构、CTA 和标题样式仍然模糊
每个未明确的维度都意味着一次碰运气。掌握多少信息,就补充多少维度。
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
# Progressively more specific prompts
prompts = [
'Write about Python.',
'Write a 200-word article about Python.',
'Write a 200-word article about Python for beginners who know no programming.',
(
'Write a 200-word article about Python for beginners who know no programming. '
'Start with a real-world analogy. Use 3 short paragraphs. '
'End with one actionable first step they can take today.'
)
]
for i, p in enumerate(prompts, 1):
print(f'Prompt {i} ({len(p)} chars): {p[:80]}...' if len(p) > 80 else f'Prompt {i}: {p}')
print()在实践中使用比较配对技巧
比较配对技巧是一种强大的调试工具。当您得到不理想的输出时:
- 保存生成不理想输出的模糊提示词
- 找出导致问题的那个维度
- 撰写一条只针对该维度的具体改写
- 运行两条提示词并比较输出
- 找出仍需修复的地方,然后加入下一条约束
这种科学方法能快速教会您:对于您的使用场景,哪些约束最重要。
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
def compare_prompts(prompt_a, prompt_b, label_a='A', label_b='B'):
client_ref = anthropic.Anthropic(api_key='sk-ant-your-key-here')
for label, prompt in [(label_a, prompt_a), (label_b, prompt_b)]:
response = client_ref.messages.create(
model='claude-opus-4-5',
max_tokens=150,
messages=[{'role': 'user', 'content': prompt}]
)
print(f'=== {label} ===')
print(prompt)
print('--- OUTPUT ---')
print(response.content[0].text)
print()
compare_prompts(
prompt_a='Explain APIs.',
prompt_b='Explain APIs in 3 sentences for a non-technical startup founder. Analogy required.',
label_a='VAGUE',
label_b='SPECIFIC'
)两分钟提示词审查
发送任何重要提示词之前,请进行这项两分钟审查。对于每个问题,如果答案是“否”,就补充缺少的细节:
- 是否指定了格式?(列表/表格/段落/JSON)
- 是否指定了长度?(字数/项目数)
- 是否描述了受众?(职位+背景)
- 目标是否清晰?(输出的用途)
- 是否至少有一条排除项?(应省略的内容)
- 是否提供了示例或模板?(如果风格很重要)
def two_minute_audit(prompt):
score = 0
checks = {
'Format specified': any(w in prompt.lower() for w in
['list', 'table', 'paragraph', 'json', 'bullet', 'sentence', 'word']),
'Length given': any(c.isdigit() for c in prompt),
'Audience named': any(w in prompt.lower() for w in
['for a', 'audience', 'targeting', 'developer', 'manager', 'beginner']),
'Exclusion added': any(w in prompt.lower() for w in
['do not', 'avoid', 'exclude', 'no ', 'without', 'never']),
'Goal stated': any(w in prompt.lower() for w in
['goal', 'purpose', 'so that', 'in order to', 'will be used']),
}
print('Prompt Audit:')
for check, passed in checks.items():
icon = 'PASS' if passed else 'FAIL'
print(f' [{icon}] {check}')
if passed: score += 1
print(f'Score: {score}/{len(checks)}')
two_minute_audit(
'Write 5 bullet-point suggestions for improving user onboarding '
'for a B2B SaaS app targeting first-time non-technical users. '
'Avoid suggestions that require engineering work. Each bullet: max 25 words.'
)构建您的提示词库
每当您写出一条能产生优秀输出的提示词,就把它保存下来。请按任务类型建立个人提示词库。
一条优秀的提示词库条目应包含:
- 带有
[AUDIENCE]、[WORD_COUNT]等占位符的提示词模板 - 它所设计的使用场景
- 所使用的模型和设置
- 说明它为何有效的备注
随着时间推移,您的提示词库会成为最有价值的 AI 生产力资产。
# Example prompt library entry
prompt_library = {
'meeting_summary': {
'template': (
'Summarize the following meeting transcript in this format:\n'
'1. Purpose: (1 sentence)\n'
'2. Decisions: (bullet list, max 5)\n'
'3. Action Items: (table: Task | Owner | Deadline)\n'
'4. Open Questions: (numbered list)\n'
'Missing info: N/A. Facts only.\n\nTranscript:\n[TRANSCRIPT]'
),
'use_case': 'Post-meeting automation for Slack or Notion',
'model': 'claude-opus-4-5',
'temperature': 0,
'notes': 'Works best with verbatim transcripts, not paraphrased notes'
}
}
# Use the template
def run_meeting_summary(transcript):
template = prompt_library['meeting_summary']['template']
return template.replace('[TRANSCRIPT]', transcript)
print(run_meeting_summary('Alice: We decided to ship v2 next Friday...')[:200])知识检查
纵观本课中的五组比较示例,哪一项单独的改动在全部五个示例中最稳定地提升了提示词质量?
模糊与具体——回顾
这五组比较示例揭示了一个一致的规律:以下因素能让提示词改写更有效:
- 输出结构是 ROI 最高的改进——务必始终定义它
- 字数/项目数可以完全消除对长度的反复协商
- 受众描述会自动校准词汇和深度
- 排除规则可以防止可预料的泛泛内容
- 部分具体化仍会留下空白——每个未明确的维度都只能靠猜测
- 提示词库可以保存成功模板,以便反复使用
用 AI 导师学习 AI Prompt Engineering — 免费
在浏览器中编写并运行真实代码,获得全天候 AI 导师的即时帮助,并在网页或应用中继续学习。
- 课程
- 53
- 课程
- 199
常见问题解答
「比较模糊提示与具体提示」课时是免费的吗?
是的 — 「比较模糊提示与具体提示」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 AI Prompt Engineering 课程的其余内容,请升级到 CoddyKit PRO。 AI Prompt Engineering 课程共包含 4 节课。
「比较模糊提示与具体提示」这节课中我会学到什么?
通过并列示例展示具体性带来的显著差异 你通过在浏览器中直接运行的动手代码来练习 AI Prompt Engineering,全天候 AI 导师会在你学习这节课的过程中回答你的问题。
学习 AI Prompt Engineering 需要有经验吗?
无需任何先前经验。CoddyKit 上的 AI Prompt Engineering 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 4 节课,共 4 节。
「比较模糊提示与具体提示」课时需要多长时间?
大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。
我能在这节 AI Prompt Engineering 课中编写并运行代码吗?
能。每节 AI Prompt Engineering 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。