mcpField
P
prompt-engineering

prompt-engineering

github.com/revitalb-portエージェントワークフロー063 回インストール10 週間前に更新
リポジトリ

prompt-engineering について

Prompt Engineeringは、信頼性の高いLLM出力を得るためのプロンプト作成と改善を支援するスキルです。構成、例、制約、コード向けのパターンに加え、テストや管理方法も扱います。

主な機能

  1. 01明確なプロンプトの原則を適用
  2. 02例と構造化出力を活用
  3. 03制約とガードレールを設定
  4. 04コード作業向けのパターンを利用
  5. 05よくあるアンチパターンを回避
  6. 06プロンプトをテストしてバージョン管理

活用シーン

  1. 01コードレビュー用システムプロンプトを作成
  2. 02機械可読なJSON出力を指定
  3. 03コード生成や修正のプロンプトを改善
  4. 04境界ケースでプロンプトの動作をテスト

インストール

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

$npx skills add https://github.com/revitalb-port/skills-registry-demo --skill prompt-engineering

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

詳細

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

LLM から信頼性の高い、高品質な出力を得るプロンプトを作成します。

基本原則

  1. 具体的にする — 曖昧なプロンプトからは曖昧な結果が返ってきます
  2. 説明するより実例を示す — 指示よりも例のほうが効果的です
  3. 出力を構成する — 希望する形式をモデルに正確に伝えます
  4. 反復する — プロンプトはコードです。テストして改善しましょう

テクニック

システムプロンプト

モデルの役割と制約を設定します。

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)を使用します
  • 十分に正確であれば、短いプロンプトのほうが長いプロンプトより高い性能を発揮することがよくあります

コメント