mcpField
P
prompt-engineering

prompt-engineering

github.com/rohitg00エージェントワークフロー2.8k193 回インストール25 週間前に更新
リポジトリ

prompt-engineering について

LLMの指示やワークフローを設計する人向けのプロンプトエンジニアリング資料です。構造化プロンプト、例、ツールの説明、テンプレート、テスト方法を扱います。

主な機能

  1. 01構造化システムプロンプト
  2. 02思考過程を促すプロンプト
  3. 03Few-shot例
  4. 04ツール利用の説明
  5. 05パラメーター化されたプロンプトテンプレート
  6. 06プロンプトテストのチェックリスト

活用シーン

  1. 01コードレビュー用プロンプトの作成
  2. 02自然言語からSQLを生成
  3. 03構造化されたモデル出力の定義

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/rohitg00/awesome-claude-code-toolkit --skill prompt-engineering

インストール後、Claude Code で/prompt-engineeringを入力して読み込まれたか確認します。

詳細

プロンプトエンジニアリング

構造化されたシステムプロンプト

You are a senior code reviewer. Your role is to analyze pull requests for:
1. Correctness - logic errors, edge cases, off-by-one errors
2. Security - injection, authentication, data exposure
3. Performance - N+1 queries, unnecessary allocations, missing indexes
4. Maintainability - naming, complexity, test coverage

For each issue found, respond with:
- Severity: critical | warning | suggestion
- File and line reference
- What is wrong
- How to fix it (with code snippet)

If the code is well-written, say so briefly. Do not invent problems.

役割、範囲、出力形式、制約を含めてシステムプロンプトを構成します。モデルがしてはいけないことを明確にします。

思考の連鎖

Analyze this database query for performance issues.

Think step by step:
1. Identify the tables and joins involved
2. Check if appropriate indexes exist for the WHERE and JOIN conditions
3. Look for full table scans or cartesian products
4. Estimate the row count at each step
5. Suggest specific index creation or query restructuring

Query:
SELECT o.*, u.name, p.title
FROM orders o
JOIN users u ON o.user_id = u.id
JOIN products p ON o.product_id = p.id
WHERE o.created_at > '2024-01-01'
AND u.country = 'US'
ORDER BY o.created_at DESC
LIMIT 50;

思考の連鎖を促すプロンプトは、モデルに中間ステップを示させることで、推論タスクの精度を向上させます。

少数ショットの例

Convert natural language to SQL. Follow these examples:

Input: "How many orders were placed last month?"
Output: SELECT COUNT(*) FROM orders WHERE created_at >= DATE_TRUNC('month', CURRENT_DATE - INTERVAL '1 month') AND created_at < DATE_TRUNC('month', CURRENT_DATE);

Input: "Top 5 customers by total spending"
Output: SELECT customer_id, SUM(total_amount) AS total_spent FROM orders GROUP BY customer_id ORDER BY total_spent DESC LIMIT 5;

Input: "Products that have never been ordered"
Output: SELECT p.* FROM products p LEFT JOIN order_items oi ON p.id = oi.product_id WHERE oi.id IS NULL;

Now convert:
Input: "Average order value per country for the last quarter"

期待する形式やエッジケースを示す、多様な例を3〜5個提示します。

ツールの使用/関数呼び出し

{
  "tools": [
    {
      "name": "search_codebase",
      "description": "Search for code patterns across the repository. Use when you need to find implementations, usages, or definitions.",
      "parameters": {
        "type": "object",
        "properties": {
          "query": {
            "type": "string",
            "description": "Regex pattern or keyword to search for"
          },
          "file_type": {
            "type": "string",
            "description": "File extension filter (e.g., 'ts', 'py')"
          }
        },
        "required": ["query"]
      }
    }
  ]
}

ツールの説明では、ツールが何をするかだけでなく、いつ使用するかも説明します。

プロンプトテンプレートのパターン

def build_review_prompt(diff: str, context: str, rules: list[str]) -> str:
    rules_text = "\n".join(f"- {rule}" for rule in rules)

    return f"""Review this code diff against the following rules:
{rules_text}

Context about the codebase:
{context}

Diff to review:

{diff}


Respond with a JSON array of findings. If no issues, return an empty array.
Each finding: {{"severity": "critical|warning|info", "line": number, "message": "string", "suggestion": "string"}}"""

アンチパターン

  • 「役に立つこと」や「最善を尽くすこと」のような曖昧な指示
  • 決定論的な出力が必要なときに、モデルに「創造的になること」を求める
  • 出力形式(JSON、Markdown、プレーンテキスト)を指定しない
  • 関係のないタスクを1つのプロンプトに詰め込む
  • 代わりに何をすべきかを伝えずに、否定形(「Xをしない」)を使う
  • 敵対的な入力やエッジケースの入力でプロンプトをテストしない

チェックリスト

  • システムプロンプトで役割、範囲、形式、制約を定義している
  • 複数ステップの推論タスクで思考の連鎖を使用している
  • 少数ショットの例で典型的なケースとエッジケースを網羅している
  • 出力形式(JSONスキーマ、Markdownなど)を明示的に指定している
  • ツールの説明で、各ツールをいつ、なぜ使用するかを説明している
  • 敵対的な入力でプロンプトをテストしている
  • タスクに適した値にTemperatureとtop_pを設定している
  • プロンプトテンプレートをハードコードされた文字列ではなく、パラメーター化している

コメント