0Pricing
AI Prompt Engineering · 课时

无害性与有用性之间的张力

应对过度拒答:设计兼顾安全性与实用性的提示词。

无害性与有用性之间的张力 是 CoddyKit 上的免费 AI Prompt Engineering 课时。 这是第 3 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 AI Prompt Engineering 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 AI Prompt Engineering 课程共包含 4 节课。

核心矛盾

每个 AI 安全系统都会面临一个根本矛盾:通过更频繁地拒绝来让模型变得更安全,也会让它对正当用户变得更无用。

一个拒绝讨论任何医疗内容的模型永远不会提供危险的健康建议——但它也无法为护士、医生或患者提供真正有用的信息。目标是做好校准:该拒绝时拒绝,该提供帮助时提供帮助。

过度拒答:真正的问题

当模型因为某些无害请求表面上类似有害请求而拒绝回答时,就会出现过度拒答。例如:

  • 拒绝解释疾病如何传播(听起来很危险,实际上是公共卫生教育)
  • 拒绝创作反派角色(这是虚构创作,并不代表认可)
  • 拒绝为锁匠学徒解释如何撬锁

过度拒答不只是令人恼火——它会让用户不再信任模型,并将用户推向安全性更低的替代方案。

通过提示实现适度拒答

系统提示可以通过澄清上下文和意图,指导模型避免过度拒答。对于正当语境下的双重用途主题,应明确授权模型进行处理。

CALIBRATED_SYSTEM_PROMPT = (
    'You are a knowledgeable assistant for healthcare professionals.\n\n'
    'Your users are nurses, doctors, and medical students. '
    'When asked about medications, dosages, procedures, or medical conditions, '
    'provide accurate, detailed information appropriate for trained professionals.\n\n'
    'Do not add excessive safety disclaimers to every response. '
    'Your users are professionals who need direct, accurate information to do their jobs. '
    'If a question is genuinely outside appropriate bounds, explain specifically why '
    'rather than giving a vague refusal.'
)

# This context dramatically improves calibration for the target audience
# Without it, the model may refuse routine clinical questions

“解释原因,而不是直接拒绝”模式

减少过度拒答最有效的提示模式之一,是指导模型:如果无法完整回答,就应解释自己能做什么、不能做什么以及原因,而不是简单地拒绝。

EXPLAIN_WHY_PROMPT = (
    'You are a helpful assistant. When handling sensitive or ambiguous requests:\n\n'
    '- If you can answer fully: do so directly.\n'
    '- If you can answer partially: provide what you can and explain what you cannot include and why.\n'
    '- If you truly cannot answer: explain specifically what boundary prevents you from answering, '
    'and suggest where the user might get this information appropriately.\n\n'
    'Do not give generic refusals like "I cannot help with that." '
    'Always be specific about what you can and cannot do.'
)

# Example of bad refusal:
# 'I cannot help with information about medications.'

# Example of good calibrated response:
# 'I can explain how ibuprofen works and standard dosing guidelines for adults.
#  For specific dosing for a patient with your described conditions, you should
#  consult a pharmacist or prescribing physician who has the full clinical picture.'

提供有帮助的替代方案

当模型必须拒绝某项请求时,最有帮助的做法是为用户真正需要的内容提供另一条可行路径。没有替代方案的拒绝会让用户陷入困境。

ALTERNATIVES_PROMPT = (
    'You are a helpful assistant. When you cannot fully fulfill a request:\n'
    '1. Acknowledge the request with empathy.\n'
    '2. Explain briefly and specifically what you can and cannot do.\n'
    '3. Offer the closest helpful alternative you can provide.\n'
    '4. Point to appropriate resources if relevant.\n\n'
    'Example: If asked to prescribe medication:\n'
    'Say: "I can explain how this class of medications works and what '
    'symptoms they address. For a prescription, you need to see a licensed '
    'physician who can evaluate your specific situation. Here is what I can '
    'tell you about the medication itself: ..."'
)

上下文是关键变量

同一个问题可能因上下文不同而有害或无害。提示工程应清晰地建立上下文,以便模型做出更好的校准决策。

# Context that changes calibration:

# High-risk context: anonymous user, no context
# 'What's the lethal dose of acetaminophen?'
# -> Model should be cautious, mention poison control

# Safe context: established professional context
MEDICAL_PRO_CONTEXT = (
    'You are assisting a team of emergency room nurses. '
    'Users ask clinical questions during patient care shifts. '
    'Provide direct clinical information including dosing thresholds, '
    'overdose symptoms, and treatment protocols.'
)
# 'What is the hepatotoxic threshold for acetaminophen?'
# -> Model should give the clinical answer directly (150 mg/kg, etc.)

# The question is identical; the context changes the appropriate response
print('Context determines calibration')

1000 位用户的心智模型

一种有助于进行校准的心智模型是:设想 1000 位不同的用户发送同一条消息。意图的分布会是什么样?

  • 如果 1000 人中有 990 人的意图是无害的:模型通常应该提供帮助
  • 如果 1000 人中有 500 人的意图是有害的:模型应该保持谨慎
  • 如果 1000 人中只要有 1 人可能造成灾难性危害:无论如何模型都应该拒绝

这种概率化的思考方式有助于避免过度拒答(拦截那 990 人)和拒答不足(助长那 10 人的有害行为)。

避免安全作秀

安全作秀指的是看起来很谨慎、实际上却无法防止危害的安全措施——同时还会让产品对正当用户变得更差。

例如:给每份食谱都添加免责声明(“食用前请咨询营养师”);在教育语境下拒绝讨论历史暴行。这些响应并不更安全——它们只是没有帮助。

# Avoid these patterns in your system prompts:

BAD_SYSTEM_PROMPT = (
    'Always add disclaimers to every response. '
    'Never discuss anything that could be dangerous. '
    'Refuse requests that mention weapons, drugs, or violence in any context. '
    'Always recommend consulting a professional for any question.'
    # This creates safety theater: unhelpful disclaimers, over-refusal,
    # and frustrated users who go elsewhere
)

GOOD_SYSTEM_PROMPT = (
    'Provide accurate, helpful information to users. '
    'Add safety information when it is directly relevant and actionable. '
    'Refuse requests only when providing the information would cause '
    'clear, concrete harm that outweighs the benefits to legitimate users. '
    'When declining, always explain specifically why and offer alternatives.'
)

将摩擦作为安全机制

与其直接拒绝,不如考虑增加摩擦:添加一个让有害用途更难实现、同时让无害用途保持顺畅的步骤。与二元的拒绝/配合相比,这种方式的校准程度更高。

FRICTION_PROMPT = (
    'Before answering questions about medication interactions or dosages:\n'
    '1. Ask: "Can you tell me a bit about the context — are you a healthcare '
    'provider, a patient, or a caregiver?"\n'
    '2. Use the answer to calibrate the detail level and framing.\n'
    '3. For patient/caregiver context: provide information with appropriate '
    'guidance to consult a prescriber for their specific situation.\n'
    '4. For healthcare provider context: provide clinical-level detail directly.\n\n'
    'This one clarifying question improves both safety and helpfulness.'
)
# Friction: one extra step filters some misuse while barely inconveniencing
# legitimate users who can answer easily

双报纸测试

双报纸测试是一种用于校准拒答的启发式方法:

  • 报纸 A(AI 安全记者):这条响应会不会被报道为有害或不负责任?
  • 报纸 B(AI 过度炒作记者):这次拒绝会不会被报道为家长式管控、没有帮助或荒谬?

经过良好校准的响应能够通过两项测试:不会被报纸 A 报道为有害,也不会被报纸 B 报道为不必要地限制过多。

测试您的校准效果

请构建一个同时包含以下内容的测试集,以衡量系统的校准效果:

  • 无害请求,应该得到回答(教育、专业和创意类请求)
  • 有害请求,应该被拒绝

请跟踪假阳性率(拒绝无害请求)和假阴性率(允许有害请求)。经过良好调校的系统在这两项指标上的数值都较低。

知识检查:过度拒答

当模型因安全问题无法完全满足请求时,建议采用什么方法?

回顾:无害性与有用性之间的张力

过度拒答是一个真实且代价高昂的问题:过于宽泛地拒绝请求的模型会让正当用户失望,并削弱用户信任。适度拒答意味着只有在具体危害明显超过对可能用户的益处时才拒绝。关键模式包括:在系统提示中建立上下文,帮助模型做出更好的决策;使用“解释原因,而不是直接拒绝”的指令;始终提供有帮助的替代方案;避免安全作秀(对所有内容都添加免责声明)。1000 位用户的心智模型和双报纸测试,都是寻找适当平衡的实用启发式方法。

常见问题解答

「无害性与有用性之间的张力」课时是免费的吗?

是的 — 「无害性与有用性之间的张力」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 AI Prompt Engineering 课程的其余内容,请升级到 CoddyKit PRO。 AI Prompt Engineering 课程共包含 4 节课。

「无害性与有用性之间的张力」这节课中我会学到什么?

应对过度拒答:设计兼顾安全性与实用性的提示词。 你通过在浏览器中直接运行的动手代码来练习 AI Prompt Engineering,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 AI Prompt Engineering 需要有经验吗?

无需任何先前经验。CoddyKit 上的 AI Prompt Engineering 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 3 节课,共 4 节。

「无害性与有用性之间的张力」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 AI Prompt Engineering 课中编写并运行代码吗?

能。每节 AI Prompt Engineering 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. CAI 原则与批评提示词
  2. 自我批评与修订模式
  3. 无害性与有用性之间的张力
  4. 在应用中实现 CAI
← 返回 AI Prompt Engineering