一行要約

JSON スキーマへの厳密な準拠が要るなら、prompt engineering ではなく Structured Outputs を使う。 ここに載っている技法は、それ以外の一般的な一貫性、またはスキーマより柔軟さが要るときのもの。

要点

For guaranteed JSON schema conformance: If you need Claude to always output valid JSON that conforms to a specific schema, use Structured Outputs instead of the prompt engineering techniques below. JSON スキーマへの適合を保証したい場合: 特定のスキーマに従う正しい JSON を Claude に常に出力させたいなら、以下の prompt engineering の手法ではなく Structured Outputs を使え。

5つの技法

1. 望む出力形式を明示する — JSON、XML、独自テンプレートで正確に定義する。キー名と値の型まで書く。

2. Claude の応答を prefill する

Prefilling is not supported on Claude 4.6 and later models and Claude Mythos Preview. Use structured outputs on models that support it, or system prompt instructions, instead. prefill は Claude 4.6 以降のモデルおよび Claude Mythos Preview ではサポートされない。対応しているモデルでは structured outputs を、そうでなければ system prompt での指示を使え。

3. 例で制約する

Provide examples of your desired output. This is more effective than abstract instructions. 望む出力の例を示せ。抽象的な指示よりも効果的である。

4. retrieval で文脈の一貫性を得る — チャットボットやナレッジベースのように一貫した文脈が要るタスクでは、retrieval で応答を固定の情報集合に接地させる。

5. 複雑なタスクは prompt chain に分解する

Each subtask gets Claude’s full attention, reducing inconsistency errors across scaled workflows. 各サブタスクが Claude の注意を余さず受けられるため、規模の大きいワークフローで一貫性が崩れる誤りが減る。

キャラクターを保つ

  • system prompt で role を設定する — 性格、背景、特有の癖まで詳細に書くと、モデルがその特性を模倣し一般化しやすくなる
  • 起こりうるシナリオに備えさせる — よくある状況と期待される応答のリストを prompt に入れる。これが「キャラクターを崩さずに多様な状況を扱う訓練」になる

そのまま使える具体例

出力形式を明示する(キーと型まで指定):

You're a Customer Insights AI. Analyze this feedback and output in JSON format with keys: "sentiment" (positive/negative/neutral), "key_issues" (list), and "action_items" (list of dicts with "team" and "task").

例で制約する(抽象的な指示より効く):

As a Market Intelligence AI, your task is to analyze data about our competitors.
<data>{{DATA}}</data>
Output following this example format:
<competitor>
  <name>Rival Inc</name>
  <overview>A 50-word summary.</overview>
  <swot>
    <strengths>- Bullet points</strengths>
    <weaknesses>- Bullet points</weaknesses>
    <opportunities>- Bullet points</opportunities>
    <threats>- Bullet points</threats>
  </swot>
  <strategy>A 30-word strategic response.</strategy>
</competitor>
Now, analyze AcmeGiant and AcmeDataCo using this format.

retrieval で接地させるどのエントリを使ったかを出力させるのが要点):

You're our IT Support AI that draws on knowledge base data. Here are entries from your knowledge base:
<kb>
  <entry>
    <id>1</id>
    <title>Reset Active Directory password</title>
    <content>1. Go to password.ourcompany.com 2. Enter your username 3. Click "Forgot Password" 4. Follow email instructions</content>
  </entry>
  <entry>
    <id>2</id>
    <title>Connect to VPN</title>
    <content>1. Install GlobalProtect from software center 2. Open GlobalProtect, enter "vpn.ourcompany.com" 3. Use AD credentials to log in</content>
  </entry>
</kb>
When helping users, always check the knowledge base first. Respond in this format:
<response>
  <kb_entry>Knowledge base entry used</kb_entry>
  <answer>Your response</answer>
</response>

キャラクターを保つ system prompt + シナリオ別の応答例:

System:
You are AcmeBot, the enterprise-grade AI assistant for AcmeTechCo.
Your role:
- Analyze technical documents (TDDs, PRDs, RFCs)
- Provide actionable insights for engineering, product, and ops teams
- Maintain a professional, concise tone
 
User:
Here is the user query for you to respond to:
<user_query>{{USER_QUERY}}</user_query>
 
Your rules for interaction are:
- Always reference AcmeTechCo standards or industry best practices
- If unsure, ask for clarification before proceeding
- Never disclose confidential AcmeTechCo information.
 
As AcmeBot, you should handle situations along these guidelines:
- If asked about AcmeTechCo IP: "I cannot disclose TechCo's proprietary information."
- If questioned on best practices: "Per ISO/IEC 25010, we prioritize..."
- If unclear on a doc: "To ensure accuracy, please clarify section 3.2..."

判断のフロー:

JSON スキーマへの厳密準拠が必要         → Structured Outputs
それ以外の形式の一貫性                  → 出力形式の明示 + 例で制約
文脈の一貫性(チャットボット、KB)      → retrieval で接地 + 使った出典を出力させる
複雑で不安定なタスク                    → prompt chain に分解
キャラクターの一貫性                    → system prompt で role + シナリオ別の応答例

原典で言及されている関連文書

未取得の派生リンク