> ## Documentation Index
> Fetch the complete documentation index at: https://factory-docs-auto-sync-jp-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# モデル別プロンプト作成

> Claude、GPT、その他のモデルからより良い結果を得るためのモデル固有のプロンプト技法。

異なるAIモデルは、異なるプロンプティングスタイルによりよく反応します。このガイドでは、モデル固有のテクニックを取り上げ、すぐに使用できるプロンプトリファイナースキルを提供します。

<Info>
  **どこでも動作:** これらのプロンプティング技術は、Droid CLIと[Factory App](/jp/web/getting-started/overview)の両方に適用されます。
</Info>

***

## 汎用プロンプティング原則

これらの原則は、すべてのモデルで機能します：

<AccordionGroup>
  <Accordion title="成果について具体的に指定する">
    **弱い例:** "認証のバグを修正して"

    **強い例:** "ユーザーが5分間の非アクティブ状態後にログアウトされるログインタイムアウトバグを修正してください。セッションは24時間持続する必要があります。"
  </Accordion>

  <Accordion title="指示の前にコンテキストを提供する">
    **弱い例:** "エラーハンドリングを追加して"

    **強い例:** "このAPIエンドポイントは決済処理を処理します。現在、ネットワークエラー時にサイレントクラッシュします。エラーをログに記録し、ユーザーフレンドリーなメッセージを返し、アラートをトリガーするエラーハンドリングを追加してください。"
  </Accordion>

  <Accordion title="受け入れ基準を含める">
    **弱い例:** "高速化して"

    **強い例:** "検索クエリを最適化してください。成功基準：10k件のレコードでクエリ時間100ms未満、結果精度に変更なし、既存のテストに合格。"
  </Accordion>

  <Accordion title="制約を明示的に指定する">
    **弱い例:** "このコードをリファクタリングして"

    **強い例:** "このコードをリポジトリパターンを使用してリファクタリングしてください。制約：パブリックAPIを変更しない、後方互換性を維持する、同じテストカバレッジを保つ。"
  </Accordion>
</AccordionGroup>

***

## Claude Models（Opus、Sonnet、Haiku）

Claudeモデルは、構造化された明示的な指示に優れ、特定のフォーマット パターンに特によく反応します。

### Claude向けの主要テクニック

<Steps>
  <Step title="構造化にXMLタグを使用する">
    Claudeは、複雑なプロンプトを整理するためのXMLスタイルタグに非常によく反応します：

    ```
    <context>
    This is a React application using TypeScript and Zustand for state management.
    The auth module handles user sessions and JWT tokens.
    </context>

    <task>
    Add a "remember me" checkbox to the login form that extends session duration to 30 days.
    </task>

    <requirements>
    - Store preference in localStorage
    - Update JWT expiration accordingly
    - Add unit tests for the new functionality
    </requirements>
    ```
  </Step>

  <Step title="例を専用セクションに配置する">
    特定の出力形式が必要な場合は、例を示してください：

    ```
    <example>
    Input: "user not found"
    Output: { code: "USER_NOT_FOUND", message: "The specified user does not exist", httpStatus: 404 }
    </example>

    Now handle these error cases following the same pattern:
    - Invalid password
    - Account locked
    - Session expired
    ```
  </Step>

  <Step title="複雑な推論には思考プロンプトを使用する">
    複雑な判断については、Claudeに選択肢を検討してもらいます：

    ```
    Before implementing, analyze:
    1. What are the tradeoffs between approach A and B?
    2. Which approach better fits our existing patterns?
    3. What edge cases should we consider?

    Then implement the better approach.
    ```
  </Step>
</Steps>

<Tip>
  以下のプロンプトリファイナースキルを `~/.factory/skills/` にコピーして使用してください。スキルについて詳しくは、[スキルドキュメント](/jp/cli/configuration/skills)をご覧ください。
</Tip>

### Claude プロンプトリファイナースキル

`~/.factory/skills/prompt-refiner-claude/SKILL.md` を作成してください：

````markdown theme={null}
---
name: prompt-refiner-claude
description: Refine prompts for Claude models (Opus, Sonnet, Haiku) using Anthropic's best practices. Use when preparing complex tasks for Claude.
---

# Claude Prompt Refiner

## When to Use
Invoke this skill when you have a task for Claude that:
- Involves multiple steps or files
- Requires specific output formatting
- Needs careful reasoning or analysis
- Would benefit from structured context

## Refinement Process

### 1. Analyze the Draft Prompt
Review the user's prompt for:
- [ ] Clear outcome definition
- [ ] Sufficient context
- [ ] Explicit constraints
- [ ] Success criteria

### 2. Apply Claude-Specific Patterns

**Structure with XML tags:**
- `<context>` - Background information, codebase state
- `<task>` - The specific action to take
- `<requirements>` - Must-have criteria
- `<constraints>` - Limitations and boundaries
- `<examples>` - Sample inputs/outputs if helpful

**Ordering matters:**
1. Context first (what exists)
2. Task second (what to do)
3. Requirements third (how to do it)
4. Examples last (clarifying edge cases)

### 3. Enhance for Reasoning
For complex tasks, add:
- "Think through the approach before implementing"
- "Consider these edge cases: ..."
- "Explain your reasoning for key decisions"

### 4. Output the Refined Prompt
Present the improved prompt with:
- Clear section headers
- XML tags where beneficial
- Specific, measurable criteria

## Example Transformation

**Before:**
"Add caching to the API"

**After:**
```
<context>
/api/products エンドポイントは現在、リクエストごとにデータベースを照会しています。
平均応答時間は200msです。アプリの他のキャッシュにはRedisを使用しています。
</context>

<task>
データベース負荷を軽減するために、/api/products エンドポイントにRedisキャッシュを追加します。
</task>

<requirements>
- キャッシュTTLは5分
- 商品が更新された際のキャッシュ無効化
- Redisが利用できない場合のデータベースへの適切なフォールバック
- キャッシュヒット/ミスメトリクスのログ追加
</requirements>

<constraints>
- レスポンス形式を変更しないこと
- 既存の統合テストを通すこと
- src/lib/redis.ts から既存のRedis接続を使用すること
</constraints>
```
````

## GPT モデル（GPT-5、GPT-5.1、Codex）

GPTモデルは明確なシステムレベルのコンテキストで優秀な性能を発揮し、明示的な役割の設定から恩恵を受けます。

### GPTの主要なテクニック

<Steps>
  <Step title="役割を明示的に設定する">
    GPTモデルは明確な役割定義によく反応します：

    ```
    You are a senior TypeScript developer reviewing code for a production e-commerce platform.
    Focus on: type safety, error handling, and performance.

    Review this checkout flow implementation...
    ```
  </Step>

  <Step title="手順には番号付きステップを使用する">
    GPTは番号付き指示を確実に従います：

    ```
    Complete these steps in order:
    1. Read the current implementation in src/auth/
    2. Identify all places where tokens are validated
    3. Create a centralized token validation utility
    4. Update all call sites to use the new utility
    5. Add unit tests for the utility
    6. Run the test suite and fix any failures
    ```
  </Step>

  <Step title="出力形式について明確に指定する">
    欲しいものを正確に指定してください：

    ```
    Return your analysis as a markdown document with these sections:
    ## Summary (2-3 sentences)
    ## Issues Found (bulleted list)
    ## Recommended Changes (numbered, in priority order)
    ## Code Examples (if applicable)
    ```
  </Step>
</Steps>

### GPT プロンプト改善スキル

`~/.factory/skills/prompt-refiner-gpt/SKILL.md` を作成します:

````markdown theme={null}
---
name: prompt-refiner-gpt
description: Refine prompts for GPT models (GPT-5, GPT-5.1, Codex) using OpenAI's best practices. Use when preparing complex tasks for GPT.
---

# GPT Prompt Refiner

## When to Use
Invoke this skill when you have a task for GPT that:
- Requires a specific persona or expertise
- Involves procedural steps
- Needs structured output
- Benefits from explicit examples

## Refinement Process

### 1. Analyze the Draft Prompt
Review for:
- [ ] Clear role/persona definition
- [ ] Step-by-step breakdown (if procedural)
- [ ] Output format specification
- [ ] Concrete examples

### 2. Apply GPT-Specific Patterns

**Role framing:**
Start with "You are a [specific role] working on [specific context]..."

**Numbered procedures:**
Break complex tasks into numbered steps that build on each other.

**Output specification:**
Be explicit: "Return as JSON", "Format as markdown with headers", etc.

**Chain of thought:**
For reasoning tasks, add: "Think through this step by step."

### 3. Structure the Prompt

**Effective order for GPT:**
1. Role definition (who/what)
2. Context (background info)
3. Task (what to do)
4. Steps (how to do it, if procedural)
5. Output format (what to return)
6. Examples (optional clarification)

### 4. Output the Refined Prompt
Present with:
- Clear role statement
- Numbered steps where applicable
- Explicit output requirements

## Example Transformation

**Before:**
"Review this code for security issues"

**After:**
```
あなたはNode.js決済処理サービスのセキュリティ監査を実施するシニアセキュリティエンジニアです。

コンテキスト: このサービスはクレジットカード取引を処理し、StripeのAPIと通信します。AWS ECSで実行されます。

タスク: セキュリティ脆弱性について`src/payments/`のコードをレビューしてください。

手順:
1. すべてのエンドポイントで適切な入力検証を確認
2. シークレットがハードコード化されていたり、ログに記録されていないことを確認
3. 認証と認可ロジックをレビュー
4. SQLインジェクションとXSS脆弱性を確認
5. 機密情報を漏洩しない適切なエラーハンドリングを確認

出力形式:
以下の内容でmarkdown形式のセキュリティレポートを返してください:
- **Critical**: デプロイ前に修正が必要な問題
- **High**: 速やかに対処すべき重大なリスク
- **Medium**: 検討すべき改善点
- **Recommendations**: 一般的なセキュリティ強化策

各問題について以下を含めてください:
- ファイルと行番号
- 脆弱性の説明
- コード例を含む推奨修正方法
```
````

***

## Gemini モデル

Gemini モデルは長いコンテキストを適切に処理し、構造化された推論で効果的に動作します。

### Gemini の主要テクニック

<Steps>
  <Step title="長いコンテキストを活用する">
    Gemini は広範囲なコンテキストを処理できます。より多くの背景情報を含めることを恐れる必要はありません：

    ```
    Here's the full module structure for context:
    [include relevant files]

    Based on these patterns, implement a new service that...
    ```
  </Step>

  <Step title="推論レベルを効果的に使用する">
    Geminiは低推論と高推論をサポートしています。高推論は以下の場合に使用してください：

    * アーキテクチャの意思決定
    * 複雑なデバッグ
    * 多段階の計画立案

    低推論は以下の場合に使用してください：

    * 単純な実装
    * 仕様書からのコード生成
    * 定期的なリファクタリング
  </Step>
</Steps>

***

## モデル選択戦略

タスクに適したモデルを選択してください：

| タスクタイプ           | 推奨モデル                        | 推論レベル    |
| ---------------- | ---------------------------- | -------- |
| **複雑なアーキテクチャ**   | Opus 4.7 または Opus 4.6        | High-Max |
| **機能実装**         | Sonnet 4.5 または GPT-5.1-Codex | Medium   |
| **簡単な編集、フォーマット** | Haiku 4.5                    | Off/Low  |
| **コードレビュー**      | GPT-5.1-Codex-Max            | High     |
| **一括自動化**        | GLM-5 (Droid Core)           | None     |
| **調査/分析**        | Gemini 3 Pro                 | High     |

***

## 独自のプロンプトリファイナーの作成

チーム固有のニーズに対応するため、カスタムプロンプトリファイナーを作成してください：

````markdown theme={null}
---
name: prompt-refiner-team
description: Refine prompts using our team's conventions and project context.
---

# Team Prompt Refiner

## Our Conventions
- We use the repository pattern
- All services have interfaces defined first
- Tests use our custom test utilities from @/test-utils

## Checklist for Prompts
1. [ ] References relevant existing code
2. [ ] Specifies which layer (API, service, repository)
3. [ ] Mentions related tests to update
4. [ ] Includes acceptance criteria

## Template
```
コンテキスト: [何が存在するか、どのモジュール/レイヤーか]
タスク: [具体的なアクション]
従うべきパターン: [既存の類似コードを参考にする]
テスト: [追加/更新すべきテスト]
完了条件: [受け入れ基準]
```
````

***

## クイック リファレンス カード

### Claude (Opus/Sonnet/Haiku)

* ✅ 構造化のためのXMLタグ
* ✅ 指示の前にコンテキスト
* ✅ 専用セクションでの例
* ✅ 推論のための「Think through...」

### GPT (GPT-5/Codex)

* ✅ ロール設定（「You are a...」）
* ✅ 番号付きステップ手順
* ✅ 明示的な出力形式
* ✅ 推論のための「Step by step」

### Gemini

* ✅ 広範囲なコンテキストの包含
* ✅ 低/高推論レベル
* ✅ 構造化された出力リクエスト

***

## 次のステップ

<CardGroup cols={2}>
  <Card title="セットアップ チェックリスト" href="/jp/guides/power-user/setup-checklist" icon="list-check">
    パワーユーザー設定を完了する
  </Card>

  <Card title="トークン効率" href="/jp/guides/power-user/token-efficiency" icon="gauge-high">
    品質を保ちながらコストを削減する
  </Card>
</CardGroup>
