効果的に状況を設定する
「あなたは…」「…を前提とすると」「目標は…」といったフレーミング手法を学びます。
「効果的に状況を設定する」はCoddyKit上の無料AI Prompt Engineeringレッスンです。 これはレッスン3/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはAI Prompt Engineering学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 AI Prompt Engineeringコースには全4レッスンが含まれています。
効果的な冒頭フレーム
プロンプトの最初の文が最も重要です。その文によって、モデルが動作するコンテキスト、つまり後に続くすべてを解釈する際の視点が決まります。
効果的な冒頭フレームには、「あなたは…です」、「コンテキストは…です」、「…を前提とすると」、「目標は…です」などがあります。それぞれ、実際のタスクを始める前に、異なる側面のコンテキストを有効にします。
「あなたは…です」フレーム
「あなたは…です」フレームは、モデルにペルソナを割り当てます。これにより、その役割に関連する語彙、推論スタイル、優先事項が有効になります。
重要なのは、具体的にすることです。「あなたは専門家です」では弱い表現です。「あなたは経験10年のシニアPythonエンジニアで、巧妙さよりも可読性を重視します」なら強い表現になります。
ペルソナフレームは、必要とする特定の思考方法やコミュニケーション方法をペルソナが示唆する場合に、最も効果を発揮します。
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
persona_prompts = [
'You are a Socratic philosophy professor. Ask 3 probing questions about this claim: AI will replace programmers.',
'You are a skeptical venture capitalist who has seen 500 pitches. Give brutal feedback on this pitch: We are building an AI writing assistant.',
'You are a patient kindergarten teacher. Explain what a computer does in 3 sentences for 5-year-olds.'
]
for prompt in persona_prompts:
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=150,
messages=[{'role': 'user', 'content': prompt}]
)
print(f'--- Persona ---')
print(prompt[:80] + '...')
print(response.content[0].text.strip())
print()システムメッセージの「あなたは…」フレーム
ペルソナフレームを配置する最も効果的な場所は、ユーザーのターンではなくシステムメッセージです。システムメッセージのペルソナは会話全体を通して有効なため、繰り返し指定する必要はありません。
巧みに作成したシステムペルソナは、何十もの追加質問に対するAIアシスタントの応答方法を完全に変えられます。
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
# Persona set once in system; stays active for all turns
system_persona = (
'You are Marcus, a senior software architect at a Fortune 500 company. '
'You have 20 years of experience with distributed systems. '
'Your communication style: direct, pragmatic, no buzzwords. '
'You always ask about scale and failure modes before giving architecture advice. '
'If a question lacks context, ask one clarifying question before answering.'
)
response = client.chat.completions.create(
model='gpt-4o',
messages=[
{'role': 'system', 'content': system_persona},
{'role': 'user', 'content': 'Should we use microservices for our new product?'}
]
)
print(response.choices[0].message.content)「コンテキストは…」フレーム
コンテキストは…フレームは、ペルソナを割り当てずに状況の背景を設定します。キャラクターになりきらせるのではなく、あなたの具体的な状況についてモデルに推論させたい場合に使用します。
これは、モデル自身として推論させながら、制約を十分に認識させたい技術的・分析的なタスクで特に効果的です。
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=300,
messages=[{
'role': 'user',
'content': (
'The context is: we are a 5-person startup with $2M in seed funding. '
'Our Python monolith handles 10,000 users and is starting to show performance issues. '
'We have one backend engineer and cannot hire more for 6 months. '
'We need to choose between refactoring the monolith vs migrating to microservices.\n\n'
'Give a recommendation with 3 supporting reasons. Be direct.'
)
}]
)
print(response.content[0].text)「…を前提とすると」フレーム
…を前提とするとフレームは、回答全体を方向づける前提や仮定を設定します。タスクの目的上、モデルが真実として扱わなければならない事実を確立するために使用します。
これは、特定の出発点からモデルに推論させる必要がある仮説分析、条件付きの計画、シナリオベースの文章作成で強力です。
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
scenarios = [
'Given that our user base will grow 10x in 6 months, what architecture changes should we make today?',
'Given that we must launch in 2 weeks with the current team, which features should we cut from the MVP?',
'Given that our API key was exposed publicly for 3 hours, what steps should we take in the next 24 hours?'
]
for scenario in scenarios:
response = client.chat.completions.create(
model='gpt-4o',
max_tokens=120,
messages=[{
'role': 'user',
'content': scenario + ' (Answer in 3 bullet points.)'
}]
)
print(f'Scenario: {scenario[:60]}...')
print(response.choices[0].message.content.strip())
print()「目的は…」フレーム
目的は…フレームは、出力が最終的に何のために使われるかを示します。タスクの指示とは異なり、この出力がなぜ必要なのか、そして何を達成しなければならないのかを説明します。
このフレームにより、モデルは説得の強さ、先回りして扱うべき反論、含める詳細と省く詳細など、細かな判断をより適切に行えるようになります。
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
goal_frames = [
(
'The goal is to get the reader to schedule a 30-minute demo call. '
'Write a 100-word cold outreach email for our AI data pipeline tool '
'targeting data engineers at e-commerce companies.'
),
(
'The goal is to help the reader pass a senior Python interview at a FAANG company. '
'Explain Python decorators with one conceptual explanation and one practical code example.'
)
]
for prompt in goal_frames:
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=200,
messages=[{'role': 'user', 'content': prompt}]
)
print('--- Goal Frame ---')
print(prompt[:80] + '...')
print(response.content[0].text.strip())
print()冒頭フレームの組み合わせ
最も強力なプロンプトでは、タスクの指示の前に複数の冒頭フレームを組み合わせます。一般的な高性能の構成は次のとおりです。
- あなたは… [ペルソナ]
- コンテキストは… [状況]
- 目的は… [最終的な目的]
- …を前提とすると [重要な仮定または制約]
- [タスクの指示]
それぞれのフレームが方向づけの層を加えます。組み合わせることで、モデルが推測しなければならないことを大幅に減らせます。
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
combined_frame_prompt = (
'You are a senior product manager with 10 years of B2B SaaS experience.\n'
'The context is: our team is debating whether to build a native mobile app '
'or keep investing in our responsive web app.\n'
'The goal is: to help our leadership team make a clear go/no-go decision at '
'next week\'s board meeting.\n'
'Given that: we have 3 engineers, $300k runway, and 85% of current users are on desktop.\n\n'
'Write a 250-word recommendation memo with a clear position (build or wait) '
'and 3 supporting arguments. End with one risk to monitor.'
)
response = client.chat.completions.create(
model='gpt-4o',
messages=[{'role': 'user', 'content': combined_frame_prompt}]
)
print(response.choices[0].message.content)トーンと語り口を設定するフレーミング
冒頭フレームは、「トーン」という言葉をまったく使わずに、トーンや語り口を設定することもできます。ペルソナと状況を説明することで、暗黙的に文体が決まります。
- 「あなたは、悩んでいる学生に話しかける、温かく辛抱強いメンターです」 → 自動的に温かく、励ますような語り口になります
- 「あなたは、妥協を許さない軍の兵站担当将校です」 → 自動的に簡潔で正確な語り口になります
- 「あなたは、Wired向けに記事を書く、機知に富んだテクノロジージャーナリストです」 → 自動的に機知に富み、分かりやすい語り口になります
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
frames = [
'You are a warm, patient mentor. Explain why learning to code is hard but worth it.',
'You are a no-nonsense military logistics officer. Explain why learning to code is hard but worth it.',
'You are a witty tech journalist writing for Wired. Explain why learning to code is hard but worth it.'
]
for frame in frames:
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=80,
messages=[{'role': 'user', 'content': frame + ' (2 sentences only)'}]
)
print(f'Frame: {frame[:55]}...')
print(response.content[0].text.strip())
print()分析の厳密さを高めるフレーミング
熱心な同意ではなく、厳密で批判的な分析が必要な場合は、懐疑的または分析的な思考姿勢を明示的に引き出すフレームから始めます。
- 「あなたは、欠点を見つけることが役目の批判的なレビュアーです…」
- 「悪魔の代弁者として、次の内容に異議を唱えてください…」
- 「一般的な通説と反対の立場を仮定し、論じてください…」
- 「…に反対する最も弱い主張を、最も説得力のある形にして示してください…」
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
analytical_frames = [
'You are a critical reviewer whose job is to find fatal flaws. Review this startup idea: a subscription box for AI prompt templates.',
'Play devil\'s advocate. Challenge this claim: AI will make every knowledge worker 10x more productive.',
'Steelman the weakest argument against remote work, then give the strongest counter-argument.'
]
for frame in analytical_frames:
response = client.chat.completions.create(
model='gpt-4o',
max_tokens=120,
messages=[{'role': 'user', 'content': frame + ' (3 sentences max)'}]
)
print(f'Frame type: analytical/critical')
print(f'Prompt: {frame[:60]}...')
print(response.choices[0].message.content.strip())
print()ペルソナフレームを使わない場合
ペルソナフレームが常に適切なツールとは限りません。次のような場合は避けてください。
- 客観的なデータ抽出が必要な場合 — ペルソナによって偏りが生じます
- 構造化データを処理する場合 — ペルソナが注意をそらします
- タスクが純粋に機械的な場合 — 推論が必要ありません
- モデル本来の評価が欲しい場合 — ペルソナによって意見が方向づけられます
「このCSVをJSONに変換してください」や「この段落の文の数を数えてください」のようなタスクでは、フレームは必要ありません。指示だけで十分です。
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
# Persona frame is unhelpful here — just adds tokens
prompt_with_unnecessary_frame = (
'You are an expert data processing specialist with years of experience. '
'Convert the following to JSON: Name: Alice, Age: 30, City: London'
)
# Clean, direct instruction
prompt_direct = (
'Convert to a JSON object with keys name, age, city:\n'
'Name: Alice, Age: 30, City: London'
)
for label, prompt in [('WITH UNNECESSARY FRAME', prompt_with_unnecessary_frame), ('DIRECT', prompt_direct)]:
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=50,
messages=[{'role': 'user', 'content': prompt}]
)
print(f'[{label}]')
print(response.content[0].text.strip())
print()フレームをテストする
自分の用途にどのフレームが適しているかを学ぶ最善の方法は、A/Bテストを実施することです。同じタスクに異なる冒頭フレームを使い、出力を比較します。
次の観点をテストしてください。
- フレームなしとペルソナフレーム
- 曖昧なペルソナと具体的なペルソナ
- コンテキストフレームのみと、コンテキストフレーム+目的フレーム
- 1つのフレームと、組み合わせたフレーム
自分の業務の各タスクカテゴリで、どのフレームが最適な出力を生むかを記録しておきましょう。
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
task = 'Explain the pros and cons of using TypeScript over JavaScript.'
frames = {
'No frame': task,
'Persona frame': f'You are a TypeScript advocate who also knows JavaScript deeply. {task}',
'Goal frame': f'The goal is to help a JavaScript developer decide if switching to TypeScript is worth it. {task}',
'Combined frame': f'You are a pragmatic senior engineer. The goal is to help a JavaScript developer decide. {task} Give a balanced view in 3 bullet points.'
}
for label, prompt in frames.items():
response = client.chat.completions.create(
model='gpt-4o', max_tokens=80,
messages=[{'role': 'user', 'content': prompt}]
)
print(f'[{label}]: {response.choices[0].message.content.strip()[:120]}...')
print()知識チェック
ある開発者が、自分のスタートアップのピッチデックに対して、励ますものでもバランスの取れたものでもなく、純粋に敵対的で厳しい批評をAIに求めています。この目的に最も適した冒頭フレームはどれですか。
状況設定 — まとめ
冒頭フレームは、タスクの指示を読む前にモデルの方向づけを行います。最も効果的な4つのフレームは次のとおりです。
- 「あなたは…」:具体的な専門知識、コミュニケーションスタイル、優先事項を持つペルソナを割り当てます
- 「コンテキストは…」:ペルソナを割り当てずに状況の背景を設定します
- 「…を前提とすると」:モデルが真実として扱わなければならない前提や制約を確立します
- 「目的は…」:出力が最終的に何のために使われるかを定義します
複雑なタスクではフレームを組み合わせてください。純粋に機械的なタスクではフレームを使わないでください。フレームのバリエーションをテストし、自分の用途に最適なものを見つけましょう。
よくある質問
「効果的に状況を設定する」レッスンは無料ですか?
はい。「効果的に状況を設定する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、AI Prompt Engineeringコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 AI Prompt Engineeringコースには全4レッスンが含まれています。
「効果的に状況を設定する」で何を学びますか?
「あなたは…」「…を前提とすると」「目標は…」といったフレーミング手法を学びます。 ブラウザで直接実行するハンズオンコードでAI Prompt Engineeringを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
AI Prompt Engineeringを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのAI Prompt Engineeringは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン3/4です。
「効果的に状況を設定する」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このAI Prompt Engineeringレッスンでコードを書いて実行できますか?
はい。すべてのAI Prompt Engineeringレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。
このコースのすべてのレッスン
- AI プロンプトにおけるコンテキストとは
- 背景情報を提供する
- 効果的に状況を設定する
- コンテキストの長さと関連性