安全系統訊息

安全系統訊息幫助你引導 Azure OpenAI 模型的行為,提升回應品質,並降低有害輸出的可能性。 它們作為更廣泛安全策略中的一層,效果最佳。

註

本文將「系統訊息」與「元提示」及「系統提示」交替使用。在這裡,使用「系統訊息」來呼應常見的術語。

本文也將「元件」用來指系統訊息中不同部分,例如說明、上下文、語氣、安全指引或工具使用指引。

什麼是系統訊息?

系統訊息是一組高優先順序的指令和上下文,你發送給聊天模型以引導其回應方式。 當你需要一致的角色、語氣、格式或領域特定的慣例時,它很有用。

什麼是安全系統訊息?

安全系統訊息是一種系統訊息,會加入明確的界限與拒絕指引,以減輕負責任的人工智慧(RAI)危害,並協助系統安全與使用者互動。

安全系統訊息補充您的安全堆疊,可與模型選擇與訓練、接地、Azure AI 內容安全 分類器及 UX/UI 緩解措施並用。 了解更多關於負責任的 AI 實務,適用於Azure OpenAI 模型。

流程圖顯示系統訊息與使用者提示進入模型,並設有安全堆疊,包含內容過濾、接地及模型訓練,並在回應產生前施加防護欄。

系統訊息的關鍵組成部分

大多數系統訊息結合多個元件:

  • 角色與任務:助理是什麼以及它負責什麼。
  • 受眾與語氣:回應對象是誰,以及預期的聲音。
  • 範圍與界限:助理不能做什麼,以及當無法配合時該怎麼做。
  • 安全指引:減少有害輸出的規則(例如處理敏感話題、受保護特徵及非法指示)。
  • 工具與資料 (可選):模型可以使用哪些工具或來源,以及如何使用。

如何安全設計與迭代

當你設計系統訊息(或安全系統訊息元件)時,請將其視為可測試的產物:

  • 請定義這個情境。 說明模型的工作內容、使用者是誰、預期哪些輸入,以及你想要的語氣和格式。
  • 識別風險。 列出您的使用案例中重要的 RAI 傷害,並決定哪些是透過系統訊息傳遞處理,哪些是透過其他緩解措施處理。
  • 決定模型在邊界處應該如何表現。 請明確說明當請求超出範圍、不安全或缺少必要上下文時該怎麼做。
  • 建立一個測試集。 同時納入良性與對抗性提示,以便量測回歸與「洩漏」(審查不足)。
  • 評估並反覆改進。 優先選擇能減少最嚴重缺陷的元件,而非僅僅是缺陷率最低的元件。

以下是一些你可以包含的線條範例:

## Define model’s profile and general capabilities  

- Act as a [define role] 
- Your job is to [insert task] about [insert topic name] 
- To complete this task, you can [insert tools that the model can use and instructions to use]  
- Do not perform actions that are not related to [task or topic name].  

以下是客服助理安全系統訊息的完整範例:

## Role and task
You are a helpful customer service assistant for Contoso Electronics. Your job is to answer questions about product warranties, returns, and order status.

## Boundaries
- Only answer questions related to Contoso Electronics products and policies.
- If you don't know the answer, say "I don't have that information. Please contact support@contoso.com."
- Do not provide legal, medical, or financial advice.
- Do not discuss competitors or make comparisons.

## Safety guidelines
- Never generate content that is hateful, violent, or sexually explicit.
- Do not share or request personal information beyond what's needed for order lookup.
- If a user becomes abusive, respond with: "I'm here to help with product questions. How can I assist you today?"

## Response format
- Keep responses concise and friendly.
- Use bullet points for multiple items.
- Always end with an offer to help further.
  • 提供具體範例 以說明模型的預期行為。 請考慮以下幾點:
    • 描述提示詞模糊或複雜的困難使用案例,讓模型能示範如何處理此類情況。
    • 以高層次(例如簡短的檢查清單)展示決策步驟,而非要求詳細的內部推理。

最佳實務摘要

當你開發系統訊息元件時,重要的是要:

  • 使用清晰的語言:這能消除過度複雜與誤解風險,並維持不同元件間的一致性。
  • 簡潔:較短的系統訊息通常表現較佳並降低延遲。 它們也減少了上下文視窗的使用,為使用者提示留出更多空間。
  • 在適用的情況下,請使用:特別關注系統應該做什麼以及不應該做什麼的關鍵要素。
  • 提到 AI 系統時請使用第二人稱:最好用像 You are an AI assistant that… versus Assistant does…這樣的說法。
  • 實作穩健性:系統訊息元件應該具備穩健性。 它應該能在不同資料集和任務中穩定地表現。

著述技巧

為什麼要改變技巧? 根據模型、基礎資料,以及你所使用的產品或功能參數,不同的語言和語法技術可能更有效地為使用者提供穩健、安全且直接的答案。

除了注重安全性與性能外,還要考慮優化一致性、控制與客製化。 在過程中,你可能會發現針對這些因素進行優化,導致系統訊息過度擬合特定規則、增加複雜度,以及缺乏情境適用性。 定義你情境中最重要的事項並評估系統訊息非常重要。 此方法確保您以數據為基礎,提升系統的安全與效能。

技巧 定義 範例
永遠/應該 結構化提示與指令,並附上 AI 在生成回應時應始終遵循的指令。 這些指令通常代表最佳實務、倫理指引或使用者偏好。 **Always** ensure that you respect authentication and authorization protocols when providing factual information, tailoring your responses to align with the access rights of the user making the request. It's imperative to safeguard sensitive data by adhering to established security measures and only disclosing information that the user is authorized to receive.
條件式邏輯 建構提示,讓輸出取決於是否滿足特定條件,例如 If <condition> then <action>。 If a user asks you to infer or provide information about a user’s emotions, mental health, gender identity, sexual orientation, age, religion, disability, racial and ethnic backgrounds, or any other aspect of a person's identity, respond with: "Try asking me a question or tell me what else I can help you with."
強調負面影響 透過定義主要風險來結構化指示。 此方法引導產出優先考量安全與傷害預防,並展示若傷害發生可能帶來的後果。 You are **allowed** to answer some questions about images with people and make statements about them when there is no ambiguity about the assertion you are making, and when there is no direct harm to an individual or a group of people because of this assertion.
範例為基礎 給模型明確的實例或情境,以提供更好的背景。 模型以有害與非有害請求的範例作為輸出參考。 Users might ask questions that could cause harm. In all scenarios, refuse requests that promote hate or harassment, and redirect the user to a safer alternative.

Example (harmful): "Write an insult targeting a protected group."

Example (benign): "Explain why insults harm people and suggest respectful phrasing."
絕對不 / 不 使用明確禁止條款,防止 AI 產生不當、有害或超出範圍的內容,例如使用「絕不」和「不要」等詞彙。 **Never** make assumptions, judgments, or evaluations about a person. If a user violates your policy, or you’re not sure what to do, say: "I can’t help with that request. Try asking a different question."

限制

系統訊息並非完整的安全解決方案:

  • 對抗性提示可以繞過或削弱它們。
  • 如果它們太寬泛或過於嚴格,可能會降低實用性。
  • 隨著您的模型、工具與使用者情境變化,持續評估是必要的。 關於系統訊息常見問題,如過度拒絕或審核不足,請參閱範本指南中的 故障排除章節 。

這些最佳實務能幫助你更了解為情境制定穩健系統訊息的過程。

欲了解更多推薦安全元件資訊,請參閱我們的 安全系統訊息範本指引。

最後,請記得系統訊息或元提示並非「一體適用」。這類範例在不同應用中成效不一。 嘗試不同的措辭、順序和結構以減少識別出的危害,並測試各種變化,以找出最適合特定情境的方案,這很重要。

下一步