Loading...
    • 開發者指南
    • API 參考
    • MCP
    • 資源
    • 發行說明
    Search...
    ⌘K
    入門
    Claude 簡介快速開始
    模型與定價
    模型概覽選擇模型Claude 4.6 新功能遷移指南模型棄用定價
    使用 Claude 構建
    功能概覽使用 Messages API處理停止原因提示詞最佳實踐
    上下文管理
    上下文視窗壓縮上下文編輯
    功能
    提示詞快取延伸思考自適應思考思考力度串流訊息批次處理引用多語言支援Token 計數嵌入視覺PDF 支援Files API搜尋結果結構化輸出
    工具
    概覽如何實作工具使用細粒度工具串流Bash 工具程式碼執行工具程式化工具呼叫電腦使用工具文字編輯器工具網頁擷取工具網頁搜尋工具記憶工具工具搜尋工具
    Agent Skills
    概覽快速開始最佳實踐企業級 Skills透過 API 使用 Skills
    Agent SDK
    概覽快速開始TypeScript SDKTypeScript V2(預覽版)Python SDK遷移指南
    API 中的 MCP
    MCP 連接器遠端 MCP 伺服器
    第三方平台上的 Claude
    Amazon BedrockMicrosoft FoundryVertex AI
    提示詞工程
    概覽提示詞產生器使用提示詞範本提示詞改進器清晰直接使用範例(多範例提示)讓 Claude 思考(CoT)使用 XML 標籤賦予 Claude 角色(系統提示詞)串聯複雜提示詞長上下文技巧延伸思考技巧
    測試與評估
    定義成功標準開發測試案例使用評估工具降低延遲
    強化防護機制
    減少幻覺提高輸出一致性防範越獄攻擊串流拒絕減少提示詞洩漏讓 Claude 保持角色
    管理與監控
    Admin API 概覽資料駐留工作區用量與成本 APIClaude Code Analytics API零資料保留
    Console
    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
    • Catalog
    • 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
    • Catalog
    • 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
    提示詞工程

    使用 XML 標籤來結構化您的提示詞

    了解如何使用 XML 標籤來改進提示詞的結構和清晰度,幫助 Claude 更準確地解析您的請求。

    While these tips apply broadly to all Claude models, you can find prompting tips specific to extended thinking models here.

    當您的提示詞涉及多個組件(如上下文、指令和範例)時,XML 標籤可以改變遊戲規則。它們幫助 Claude 更準確地解析您的提示詞,從而產生更高品質的輸出。

    XML 提示:使用 <instructions>、<example> 和 <formatting> 等標籤來清楚地分隔提示詞的不同部分。這可以防止 Claude 將指令與範例或上下文混淆。

    為什麼使用 XML 標籤?

    • 清晰度: 清楚地分隔提示詞的不同部分,並確保您的提示詞結構良好。
    • 準確性: 減少由 Claude 誤解提示詞部分而造成的錯誤。
    • 靈活性: 輕鬆找到、新增、移除或修改提示詞的部分,無需重寫所有內容。
    • 可解析性: 讓 Claude 在其輸出中使用 XML 標籤,可以更輕鬆地通過後處理提取其回應的特定部分。
    沒有規範的「最佳」XML 標籤是 Claude 特別訓練過的,儘管我們建議您的標籤名稱應與其周圍的資訊相符。

    標籤最佳實踐

    1. 保持一致:在整個提示詞中使用相同的標籤名稱,並在談論內容時參考這些標籤名稱(例如,使用 <contract> 標籤中的合約...)。
    2. 嵌套標籤:您應該為分層內容嵌套標籤 <outer><inner></inner></outer>。
    進階使用者提示:將 XML 標籤與其他技術結合,如多次提示(<examples>)或思維鏈(<thinking>、<answer>)。這會建立超級結構化、高效能的提示詞。

    範例


    提示詞庫

    從為各種任務和使用案例精選的提示詞中獲得靈感。

    GitHub 提示詞教程

    一個充滿範例的教程,涵蓋我們文件中的提示詞工程概念。

    Google Sheets 提示詞教程

    通過互動試算表提供的更輕量級版本的提示詞工程教程。

    Was this page helpful?

    • 為什麼使用 XML 標籤?