公開日
プロンプトエンジニアリングの手法:ビジネスアプリケーションのための実践ガイド
LLMを業務プロセスの中で動かすときに重要なプロンプトのパターン。明確な構造、Few-shotの例示、構造化出力、バージョン管理、コードと同様のテストを解説します。
- 執筆者
- Ali ÖzdurmuşVeni AI 創業者
- 更新日
- 読了時間
- 読了時間 約4分

プロンプトエンジニアリングとは、モデルが受け取る指示とコンテキストを設計し、必要な出力を安定して得られるようにする取り組みです。業務アプリケーションでは、プロンプトもプロダクトの一部です。コードと同じようにバージョン管理し、テストし、レビューします。このガイドでは、最も差が出る手法を取り上げます。
プロンプトエンジニアリングの基礎
プロンプトの構成要素
効果的なプロンプトは、次の要素で構成されます。
- システム指示: モデルの役割と行動ルール
- コンテキスト: タスクに関連する背景情報
- 例: 望ましい出力形式の例
- タスク: 具体的な依頼や質問
- 出力形式: 期待する回答の構造
基本的なプロンプトの構造
[Role Definition]
You are a {field of expertise} expert.
[Context]
{Relevant information}
[Task]
{Specific request}
[Format]
{Expected output format}基本的なプロンプト手法
1. ゼロショットプロンプティング
例を示さずに、タスクを直接指定します。
Summarize the following text:
{text}向いているケース:
- 単純なタスク
- 一般的な知識に関する質問
- 分類
2. Few-Shotプロンプティング
例を添えてタスクを指定します。
Text: "This product is great, I am very satisfied"
Sentiment: Positive
Text: "It was a terrible experience, I do not recommend it"
Sentiment: Negative
Text: "It's okay for the price"
Sentiment: ?ベストプラクティス:
- 通常は3〜5個の例で十分です
- さまざまなエッジケースを含めます
- 例の順序はランダムにします
3. Chain-of-Thought(CoT)
段階的に考えさせます。
Question: A store has 15 apples. 8 apples were sold,
then 6 more apples arrived. How many apples are there?
Let's think step by step:
1. Initially there are 15 apples
2. 8 apples sold: 15 - 8 = 7 apples left
3. 6 apples arrived: 7 + 6 = 13 apples
Answer: 13 apples現在の多くのモデルには、推論モードが組み込まれています。そうしたモデルでは、プロンプトで段階的な推論を求めることよりも、目的、制約、期待する出力を明確に伝えることのほうが重要です。
4. 自己整合性(Self-Consistency)
同じ質問に対して、異なる推論経路を試します。
Solve this problem in 3 different ways and choose the most consistent answer:
[Problem]5. Tree of Thoughts(ToT)
思考を枝分かれした木として展開します。
Problem: {complex problem}
Thought 1: {approach A}
→ Sub-thought 1.1: {detail}
→ Sub-thought 1.2: {detail}
Thought 2: {approach B}
→ Sub-thought 2.1: {detail}
Evaluate and select the most suitable path.高度な手法
ReAct(推論+行動)
思考と行動のループです。
Question: How many times larger is Istanbul's population than Paris?
Thought: I need to find the population of both cities
Action: [search] Istanbul population
Observation: Istanbul population ~16 million
Thought: Now I need to find Paris population
Action: [search] Paris population
Observation: Paris population ~2.2 million
Thought: I can calculate the ratio
Action: [calculate] 16 / 2.2
Observation: 7.27
Answer: Istanbul's population is approximately 7.3 times larger than Paris.Constitutional AIプロンプティング
倫理や安全に関するルールを定義します。
System: You are a helpful assistant.
Rules:
1. Do not generate harmful content
2. Do not share personal information
3. Do not help with illegal activities
4. Always be honest
User question: {question}ロールプロンプティング
特定の専門分野を定義します。
You are a cybersecurity expert with 20 years of experience.
You have worked as a CISO in Fortune 500 companies.
You can explain technical details clearly and understandably.
User's question: {question}プロンプト最適化の戦略
1. 具体性を高める
❌ 悪い例:
Write a blog post✅ 良い例:
Target audience: Software developers
Topic: Docker container security
Length: 1500-2000 words
Tone: Technical but accessible
Format: Introduction, 5 main sections, conclusion2. 出力形式を指定する
Provide your response in this JSON format:
{
"summary": "string",
"key_points": ["string"],
"next_steps": ["string"],
"confidence_score": number
}3. ネガティブプロンプティング
望ましくない振る舞いを明示します。
Do NOT do the following:
- Give speculative information
- Make claims without citing sources
- Lead the user
- Give excessively long answers4. 区切り文字の活用
セクションを明確に区切ります。
###CONTEXT###
{context information}
###TASK###
{work to be done}
###FORMAT###
{output format}モデル別の最適化
OpenAIのGPTモデル向け
- Use System message effectively
- Use structured outputs with a JSON schema where available
- Temperature: 0.7-1.0 for creative tasks, 0.1-0.3 for analyticalClaude向け
- Use XML tags: <context>, <task>, <format>
- Put important information at the end in long context
- Use extended thinking for complex, multi-step tasksGemini向け
- Optimize for multimodal prompts
- Up-to-date information with Grounding
- Adjust Safety settingsプロンプトのテストと改善
A/Bテストのフレームワーク
Prompt A: {version 1}
Prompt B: {version 2}
Metrics:
- Accuracy: %
- Consistency: 1-5
- Latency: ms
- Token usage: #プロンプトのバージョン管理
prompt_v1.0: First version
prompt_v1.1: Typo corrections
prompt_v2.0: CoT added
prompt_v2.1: Output format changed企業でのプロンプト管理
プロンプトライブラリの作成
/prompts
/classification
- sentiment_analysis.json
- intent_detection.json
/generation
- blog_writer.json
- code_reviewer.json
/extraction
- entity_extraction.json
- data_parsing.jsonプロンプトテンプレートの仕組み
class PromptTemplate:
def __init__(self, template, variables):
self.template = template
self.variables = variables
def render(self, **kwargs):
return self.template.format(**kwargs)
# Usage
sentiment_prompt = PromptTemplate(
template="Analyze sentiment: {text}",
variables=["text"]
)よくある間違いと対処法
間違い1:あまりにも曖昧なプロンプト
問題: モデルが何を求められているか理解できない 対処: 具体的な指示と例を追加する
間違い2:非常に長いプロンプト
問題: トークン上限を超え、コストが増える 対処: 不要な情報を削り、要約を使う
間違い3:矛盾する指示
問題: モデルの振る舞いが一貫しない 対処: ルールに優先順位をつけて明確にする
間違い4:ハルシネーション
問題: モデルが作り話の情報を返す 対処: グラウンディング、出典の明示の要求、温度を下げる
まとめ
優れたプロンプトは、具体的で、構造化され、テストされています。役割を定義し、コンテキストと例を与え、出力形式を固定し、変更のたびにそれをリリースとして扱い、評価セットに対して実行します。この規律は、どんな個別のテクニックよりも重要です。
Veni AIは、企業向けに構築するすべてのAIアプリケーションの裏側にあるプロンプトを、設計し、テストし、バージョン管理しています。サービスを見る、またはチームに相談する。


