prompt-engineering について
LLM の出力の信頼性と品質を高めるプロンプト作成スキルです。エージェント開発者やモデルを扱う人向けに、構成、例、制約、反復改善を扱います。
主な機能
- 01明確で具体的なプロンプトの原則
- 02システムプロンプトと少数例
- 03構造化出力と制約のパターン
- 04コード生成・変換のテンプレート
- 05アンチパターンとテストのヒント
活用シーン
- 01コードレビューや生成用プロンプトの作成
- 02機械処理可能な JSON 応答の指定
- 03エッジケースを使ったプロンプト改善
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ spencerpauly/ awesome-cursor-skills --skill prompt-engineeringインストール後、Claude Code で/prompt-engineeringを入力して読み込まれたか確認します。
詳細
プロンプトエンジニアリング
LLM から信頼性の高い、高品質な出力を得るプロンプトを作成します。
基本原則
- 具体的にする — 曖昧なプロンプトからは曖昧な結果が返ってきます
- 説明するより実例を示す — 指示よりも例のほうが効果的です
- 出力を構成する — 希望する形式をモデルに正確に伝えます
- 反復する — プロンプトはコードです。テストして改善しましょう
テクニック
システムプロンプト
モデルの役割と制約を設定します。
You are a senior code reviewer. Review the provided code for:
1. Security vulnerabilities
2. Performance issues
3. Readability problems
For each issue found, provide:
- Severity (critical/warning/info)
- Line number
- Description
- Suggested fix
If no issues are found, respond with "No issues found."
Few-Shot の例
入力 → 出力の例を 2~3 個提示します。
Convert the user's natural language query to a SQL query.
Example 1:
Input: "How many users signed up last month?"
Output: SELECT COUNT(*) FROM users WHERE created_at >= DATE_TRUNC('month', NOW() - INTERVAL '1 month') AND created_at < DATE_TRUNC('month', NOW());
Example 2:
Input: "Show me the top 5 products by revenue"
Output: SELECT p.name, SUM(o.amount) as revenue FROM products p JOIN orders o ON o.product_id = p.id GROUP BY p.name ORDER BY revenue DESC LIMIT 5;
Now convert this query:
Input: "{user_query}"
Output:
思考の連鎖
モデルに段階的に推論するよう求めます。
Analyze this error and suggest a fix. Think step by step:
1. What does the error message mean?
2. What could cause this error?
3. What is the most likely root cause given the code context?
4. What is the fix?
構造化出力
JSON または特定の形式で出力するよう求めます。
Respond with a JSON object matching this schema:
{
"summary": "string - one sentence summary",
"sentiment": "positive | negative | neutral",
"key_topics": ["string"],
"confidence": 0.0-1.0
}
制約とガードレール
Rules:
- Only use information from the provided context
- If you don't know the answer, say "I don't know" — do not guess
- Keep responses under 200 words
- Do not include any PII in your response
コード向けのパターン
コード生成:
Write a TypeScript function that {description}.
Requirements:
- {requirement 1}
- {requirement 2}
Use these libraries: {libraries}
Follow this pattern from the codebase: {example}
コード変換:
Refactor this code to {goal}. Keep the same behavior.
Do not change the public API (function signatures, exports).
バグ修正:
This code has a bug: {description of bug}
Error: {error message}
Fix the bug. Explain what caused it in a comment.
アンチパターン
- 曖昧すぎる:「これを改善して」→「改善」の意味を具体的にします
- 長すぎる:あらゆる内容を盛り込んだ巨大なプロンプト → 焦点を絞ったプロンプトに分割します
- 矛盾している:「簡潔に、かつ詳しく」→ どちらかを選ぶか、トレードオフを定義します
- 例がない:希望する形式を示さずに複雑な形式を指定する → 例を 1~2 個追加します
- プロンプトインジェクションのリスク:区切りを付けずに生のユーザー入力を含める →
<user_input>...</user_input>のような明確な区切りを使用します
ヒント
- 決定論的なタスク(コード、分類)では温度を 0 に、創造的なタスクでは 0.7 以上に設定します
- よくあるケースだけでなく、エッジケースを使ってプロンプトをテストします
- プロンプトをバージョン管理します。プロンプトはコードと同じくらい重要です
- プログラムで応答を解析する場合は、構造化出力(JSON)を使用します
- 十分に正確であれば、短いプロンプトのほうが長いプロンプトより高い性能を発揮することがよくあります
コメント
Markdown 対応