背景情報を提供する
ドメイン知識、制約、プロジェクトの詳細を、いつどのように含めるかを学びます。
「背景情報を提供する」はCoddyKit上の無料AI Prompt Engineeringレッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはAI Prompt Engineering学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 AI Prompt Engineeringコースには全4レッスンが含まれています。
背景情報が重要な理由
背景情報は、モデルが自力では知ることのできない事実を伝えます。具体的には、プロジェクトの詳細、チームの制約、すでに行った作業、ステークホルダーの期待などです。
背景情報がなければ、モデルは想像上の一般的な状況に対して出力を生成します。背景情報があれば、あなたの状況に合わせて出力を生成します。
ドメイン知識を含めるタイミング
次のような場合は、プロンプトにドメイン知識を含めてください。
- そのトピックが業界によって複数の解釈を持つ場合
- 専門用語を扱っている場合
- 正しい答えが、ドメイン固有の規範や規制に左右される場合
- 一般的な答えではなく、分野に特化した答えが必要なのに、モデルが一般論を返す可能性がある場合
教科書全体を貼り付ける必要はありません。質問に直接関係するドメインの事実を2〜3個に要約してください。
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
domain_knowledge = (
'Domain: algorithmic trading at a regulated broker-dealer in the US. '
'Relevant rules: SEC Rule 15c3-5 (Market Access Rule) requires pre-trade risk checks. '
'Latency budget: all risk checks must complete in under 100 microseconds. '
'Stack: C++ for the matching engine, Python for strategy logic.'
)
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=300,
messages=[{
'role': 'user',
'content': (
f'{domain_knowledge}\n\n'
f'Question: How should we implement position limit checks for our order router?'
)
}]
)
print(response.content[0].text)プロジェクトの詳細を含める
プロジェクトの詳細によって、取り組んでいる作業の具体的な状況をモデルに伝えられます。重要なプロジェクトの詳細には、次のようなものがあります。
- プロジェクトの内容と現在の段階(MVP / スケール中 / 成熟段階)
- 技術スタックとアーキテクチャ
- チームの規模とスキルレベル
- スケジュールと締め切りによるプレッシャー
- 質問に影響する最近の変更や出来事
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
project_context = (
'Project: a mobile recipe app (React Native, Node.js backend, MongoDB). '
'Stage: pre-launch, 2 weeks to go live. '
'Team: 2 frontend devs, 1 backend dev, no dedicated QA. '
'Current issue: app search is slow (3-5 seconds) with 50,000 recipes in the DB. '
'Constraint: no time for a full re-architecture before launch.'
)
response = client.chat.completions.create(
model='gpt-4o',
messages=[{
'role': 'user',
'content': (
f'{project_context}\n\n'
f'Suggest 3 quick wins to improve search speed before launch. '
f'Each suggestion: what to do (1 sentence), estimated effort (hours), '
f'expected improvement.'
)
}]
)
print(response.choices[0].message.content)既存の成果物を共有する
既存の成果物を共有すると、モデルは最初からやり直すのではなく、すでに行った作業を土台にできます。次のことを求める場合は、既存の成果物を含めてください。
- 文書やコードの続きの作成または拡張
- 批評と改善案
- スタイルの一致(既存の内容の語調や形式に合わせる)
- 一貫性の確認(新しい内容が既存の構成に合っているか)
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
existing_intro = (
'At Northlight Labs, we build AI tools that work the way humans think — '
'not the other way around. Founded in 2022 by two ex-Google researchers, '
'we have helped 500 companies ship smarter products without hiring ML teams.'
)
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=200,
messages=[{
'role': 'user',
'content': (
'Here is our existing company intro paragraph:\n\n'
f'{existing_intro}\n\n'
'Write a second paragraph (matching this exact tone and style) '
'that describes our flagship product: an API that lets developers '
'add natural language search to any database with 3 lines of code. '
'Keep it under 60 words.'
)
}]
)
print(response.content[0].text)制約を最初に説明する
制約とは、モデルが従わなければならないルールです。最初に制約を示しておけば、アイデアとしては完全に妥当でも、あなたの状況では実現不可能な提案をモデルが出すのを防げます。
含めるべき制約の種類:
- 技術:「Python 3.11、サードパーティライブラリは禁止」
- 予算:「0ドル — オープンソースのみ」
- 時間:「2時間のスプリントで完了させる必要がある」
- 規制:「ログに個人を特定できる情報を含めない」
- 組織:「データベーススキーマは変更できない」
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
response = client.chat.completions.create(
model='gpt-4o',
messages=[{
'role': 'user',
'content': (
'We need to add rate limiting to our REST API.\n\n'
'Constraints:\n'
'- Python 3.11 FastAPI application\n'
'- No external dependencies beyond what is already installed (requests, pydantic, uvicorn)\n'
'- Must work as a single process (no Redis, no shared state between workers)\n'
'- Rate limit: 100 requests per minute per IP address\n'
'- If limit exceeded, return HTTP 429 with Retry-After header\n\n'
'Show me a complete implementation.'
)
}]
)
print(response.choices[0].message.content)ステークホルダーの情報
ステークホルダーの情報は、あなたの状況でほかに誰が重要なのかをモデルに伝えます。ステークホルダーによって、強調すべきリスク、対処すべき反論、成功の定義が変わります。
- 「対象読者には、AIへの投資に懐疑的なCFOが含まれます」
- 「公開前に法務チームのレビューを受けます」
- 「エンドユーザーにはアクセシビリティ上のニーズがあるため、スクリーンリーダーに対応する必要があります」
- 「CTOは、巧妙な解決策よりもシンプルな解決策を好みます」
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
stakeholder_context = (
'This proposal will be reviewed by:\n'
'1. CTO: cares about technical risk and maintainability, skeptical of microservices\n'
'2. CFO: cares about cost, wants to see clear ROI numbers\n'
'3. VP Engineering: cares about developer experience and team morale\n'
'The CTO has veto power.'
)
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=400,
messages=[{
'role': 'user',
'content': (
f'{stakeholder_context}\n\n'
f'Write a 3-paragraph executive summary for a proposal to migrate '
f'our monolith to a modular monolith (not microservices). '
f'Address each stakeholder\'s top concern in a separate paragraph.'
)
}]
)
print(response.content[0].text)時系列メソッド
複雑な状況では、時系列メソッドを使って背景情報を出来事のタイムラインとして構成します。これにより、モデルは因果関係と現在の状態を理解しやすくなります。
形式:
- 以前はどのような状況だったか
- 何が変わったのか、何が起きたのか
- 現在の状態はどうなっているか
- この経緯を踏まえて何を手伝ってほしいのか
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
chronological_background = (
'Timeline:\n'
'- 6 months ago: We launched v1 of our API with a flat pricing model ($99/month).\n'
'- 3 months ago: Power users (top 10%) started consuming 80% of compute.\n'
'- 1 month ago: We introduced usage-based pricing — power users complained loudly.\n'
'- Current: 12% of power users have churned; new signups are up 15%.\n'
'- Goal: Keep power users without losing the new-signup growth.\n'
)
response = client.chat.completions.create(
model='gpt-4o',
messages=[{
'role': 'user',
'content': (
f'{chronological_background}\n\n'
f'Suggest 3 pricing model adjustments that could address both groups. '
f'For each: describe the change, who it benefits, and the revenue risk.'
)
}]
)
print(response.choices[0].message.content)自分のデータを背景情報として使う
背景情報の最も強力な活用方法の一つは、メトリクス、ログ、出力、調査結果などの自分のデータをプロンプトに直接埋め込み、モデルが自分の具体的な数値について推論できるようにすることです。
データは必ず、整理された読みやすい形式で貼り付けてください。表や構造化されたリストが最も適しています。生のテキストをそのまま貼り付けると、モデルが解析しにくくなります。
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
metrics_data = (
'Weekly active users (WAU) last 8 weeks:\n'
'Week 1: 1,200 | Week 2: 1,350 | Week 3: 1,290 | Week 4: 1,400\n'
'Week 5: 1,380 | Week 6: 1,220 | Week 7: 1,100 | Week 8: 980\n'
'Note: We launched a pricing change in Week 5.'
)
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=300,
messages=[{
'role': 'user',
'content': (
f'{metrics_data}\n\n'
f'Analyze the trend, identify where decline began, '
f'and suggest 2 hypotheses for the cause. '
f'Be specific — reference the exact weeks in your analysis.'
)
}]
)
print(response.content[0].text)背景情報として含めてはいけないもの
背景情報にはコストがかかります。トークンを消費するためです。回答に直接影響するものだけを含めてください。
通常は不要な背景情報:
- 会社の創業物語(ブランドボイスが重要な場合を除く)
- チームの組織図(意思決定権限が重要な場合を除く)
- 意思決定の対象期間より前の古い経緯
- 使用していない技術
- 現在の質問と関係のない、すでに解決済みの問題
迷った場合は、まず一度含めて出力が改善するか確認し、その後の実行で削ってください。
# Contrast: bloated vs lean background
bloated_background = (
'Our company was founded in 2018 by Alice and Bob. '
'We have 45 employees across 3 offices. We use Jira for project management. '
'We had a product refresh in 2020. Our CTO came from Amazon. '
'We use Slack, Notion, and Linear. '
'We once tried Kubernetes but moved back to Docker Compose. '
'Question: How should we handle database connection pooling in FastAPI?'
)
lean_background = (
'Stack: FastAPI, PostgreSQL, deployed on a single 8-core server. '
'Load: ~200 concurrent users peak. '
'Current issue: seeing "too many connections" errors under load. '
'Question: How should we handle database connection pooling?'
)
print('Bloated background:', len(bloated_background.split()), 'words')
print('Lean background:', len(lean_background.split()), 'words')
print('Reduction:', round((1 - len(lean_background.split())/len(bloated_background.split()))*100), '%')読みやすさを考慮して背景情報を整形する
背景情報の整形方法は、モデルがどれだけ適切に処理できるかに影響します。ベストプラクティスは次のとおりです。
- ラベル付きのセクションを使う:
Stack:、Constraints:、Goal: - 並列する項目には箇条書きを使う
- 最も重要な情報を最初に置く
- 空行または明確なマーカーで背景情報とタスクを分ける
- 一貫した用語を使う。同じものを2つの名前で呼ばない
import openai
client = openai.OpenAI(api_key='sk-your-key-here')
# Well-formatted background
formatted_background = (
'=== BACKGROUND ===\n'
'Project: real-time chat API\n'
'Stack: Python FastAPI, WebSockets, Redis pub/sub, PostgreSQL\n'
'Scale: 10,000 concurrent connections target\n'
'Constraints: single server for now, no Kubernetes\n'
'Current problem: messages are occasionally delivered out of order\n'
'=== TASK ===\n'
'Explain the root cause of out-of-order message delivery in WebSocket pub/sub '
'and suggest the simplest fix for our stack.'
)
response = client.chat.completions.create(
model='gpt-4o',
messages=[{'role': 'user', 'content': formatted_background}]
)
print(response.choices[0].message.content)システムメッセージで再利用可能な背景情報を指定する
AIを活用したアプリケーションを構築していて、同じ背景情報をすべての会話に適用する場合は、ユーザーの各ターンで繰り返すのではなく、システムメッセージに記述してください。
この方法はより効率的で、ユーザーが毎回その情報を言い直さなくても、すべてのやり取りで一貫したコンテキストを確保できます。
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-your-key-here')
# System message carries reusable background for every user turn
system_background = (
'You are an AI assistant embedded in Northlight Labs\' internal developer portal. '
'Background: our stack is Python 3.11, FastAPI, PostgreSQL 15, Redis 7, Docker. '
'We follow Google Python style guide. All code examples must include type hints. '
'We do not use ORM — raw SQL with psycopg3. '
'Our API follows REST conventions with snake_case JSON fields.'
)
# Now every user turn gets this background automatically
response = client.messages.create(
model='claude-opus-4-5',
max_tokens=300,
system=system_background,
messages=[
{'role': 'user', 'content': 'Show me how to insert a row into the users table.'}
]
)
print(response.content[0].text)理解度チェック
プロダクトマネージャーが、AIに機能告知メールの作成を手伝ってもらおうとしています。会社の創業年、従業員数、オフィスの所在地を含めた後に、タスクを記載しています。出力を最も改善できる、欠けている背景情報の種類は何でしょうか。
背景情報の提供 — まとめ
適切な背景情報があるかどうかで、一般的なアドバイスと、実際に自分の状況に合ったアドバイスとの差が生まれます。重要な原則は次のとおりです。
- 自分の分野で正しい答えに影響するドメイン知識を含める
- プロジェクトの詳細(技術スタック、段階、チームの規模、最近の変更)を共有する
- 続きの作成やスタイルの一致が必要な場合は既存の成果物を含める
- 役に立たない提案を防ぐため、制約を最初に示す
- モデルが適切な懸念に対応できるよう、ステークホルダーの情報を含める
- 複雑な状況のコンテキストには時系列メソッドを使う
- 背景情報は簡潔に保つ。回答に影響するものだけを含める
よくある質問
「背景情報を提供する」レッスンは無料ですか?
はい。「背景情報を提供する」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、AI Prompt Engineeringコースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 AI Prompt Engineeringコースには全4レッスンが含まれています。
「背景情報を提供する」で何を学びますか?
ドメイン知識、制約、プロジェクトの詳細を、いつどのように含めるかを学びます。 ブラウザで直接実行するハンズオンコードでAI Prompt Engineeringを演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。
AI Prompt Engineeringを始めるのに経験は必要ですか?
事前経験は必要ありません。CoddyKitのAI Prompt Engineeringは初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。
「背景情報を提供する」レッスンにはどのくらい時間がかかりますか?
ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。
このAI Prompt Engineeringレッスンでコードを書いて実行できますか?
はい。すべてのAI Prompt Engineeringレッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。