Loading...
  • 建構
  • 管理
  • 模型與定價
  • 客戶端 SDK
  • API 參考
Search...
⌘K
Log in
提高輸出一致性
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Solutions

  • AI agents
  • Code modernization
  • Coding
  • Customer support
  • Education
  • Financial services
  • Government
  • Life sciences

Partners

  • Amazon Bedrock
  • Google Cloud's Vertex AI

Learn

  • Blog
  • Courses
  • Use cases
  • Connectors
  • Customer stories
  • Engineering at Anthropic
  • Events
  • Powered by Claude
  • Service partners
  • Startups program

Company

  • Anthropic
  • Careers
  • Economic Futures
  • Research
  • News
  • Responsible Scaling Policy
  • Security and compliance
  • Transparency

Learn

  • Blog
  • Courses
  • Use cases
  • Connectors
  • Customer stories
  • Engineering at Anthropic
  • Events
  • Powered by Claude
  • Service partners
  • Startups program

Help and security

  • Availability
  • Status
  • Support
  • Discord

Terms and policies

  • Privacy policy
  • Responsible disclosure policy
  • Terms of service: Commercial
  • Terms of service: Consumer
  • Usage policy
建構/強化防護欄

增加輸出一致性

學習如何使用提示工程技術來提高 Claude 回應的一致性,包括指定輸出格式、預填充回應、提供範例和使用檢索等方法。

Was this page helpful?

  • 預填充 Claude 的回應
  • 保持 Claude 的角色

為了保證 JSON 架構符合性

如果您需要 Claude 始終輸出符合特定架構的有效 JSON,請使用 Structured Outputs 而不是下面的提示工程技術。Structured Outputs 提供有保證的架構符合性,專門為此用例設計。

下面的技術對於一般輸出一致性或當您需要超越嚴格 JSON 架構的靈活性時很有用。

以下是如何使 Claude 的回應更加一致的方法:

指定所需的輸出格式

使用 JSON、XML 或自訂範本精確定義您所需的輸出格式,以便 Claude 理解您需要的每個輸出格式元素。

預填充 Claude 的回應

預填充在 Claude Mythos Preview、Claude Opus 4.7、Claude Opus 4.6 和 Claude Sonnet 4.6 上不受支援。改用 structured outputs 或系統提示指令。

使用您所需的格式預填充 Assistant 輪次。此技巧繞過 Claude 的友善前言並強制執行您的結構。

使用範例進行約束

提供您所需輸出的範例。這比抽象指令更好地訓練 Claude 的理解。

使用檢索實現上下文一致性

對於需要一致上下文的任務(例如聊天機器人、知識庫),使用檢索將 Claude 的回應固定在固定信息集中。

為複雜任務鏈接提示

將複雜任務分解為較小的、一致的子任務。每個子任務都能獲得 Claude 的全部關注,減少跨擴展工作流程的不一致錯誤。

保持 Claude 的角色

對於基於角色的應用程式,保持一致的角色需要有意的提示。

  • 使用系統提示設定角色: 使用 system prompts 定義 Claude 的角色和個性。這為一致的回應奠定了堅實的基礎。
    設置角色時,提供有關個性、背景和任何特定特徵或怪癖的詳細信息。這將幫助模型更好地模擬和推廣角色的特徵。
  • 為可能的場景準備 Claude: 在您的提示中提供常見場景和預期回應的列表。這「訓練」Claude 在不破壞角色的情況下處理各種情況。