Prompt Chaining: When One Prompt Isn’t Enough プロジェクト全体を 1 つのプロンプトに圧縮しようと試みたことがあれば、 どうやって終わるかわかりますか: requirements → solution → plan → risks → final doc ステップを踏み出し、 制約を忘れてしまい、 簡単に確認できない「自信のある」答えを与えます。 そして、何かが間違っている瞬間、どこでそのミスが起きたかは分からない。 それをワークフローを構築するように考えて、各プロンプトが組み立てライン上のステーションである:一歩入り、一歩出り、出力が次のステーションの入力になります。 Prompt Chaining In other words: you’re not asking an LLM to do “everything at once.” You’re asking it to do . one thing at a time, reliably 1) What Is Prompt Chaining? 実践とは: Prompt Chaining 大きなタスクを小さなサブタスクに分解する 各サブタスクのための専用のプロンプトの設計 構造化された出力を一つのステップから次のステップに移す Validation + Correction ステップを追加して、チェーンがドライブしないようにします。 それは基本的にLLM推論に適用された「マイクロサービス思考」です。 Single Prompt vs Prompt Chaining (in plain English) Dimension Single Prompt Prompt Chaining Complexity Good for simple, one-shot tasks Built for multi-step, real workflows Logic Model guesses the process You the process define Control Hard to steer Every step is steerable Debugging “Where did it go wrong?” You can pinpoint the broken step Context limits Easy to overflow Feed data gradually, step-by-step 複雑性 Good for simple, one-shot tasks 複数のステップ、実際のワークフローのために構築 論理 モデルはプロセスを推測する あなた the process define コントロール ステアリング ステアリング あらゆるステップがコントロール可能 Debugging 「どこで間違えたの?」 You can pinpoint the broken step. あなたは壊れたステップを見つけることができます。 文脈の限界 超流しやすい Feed data gradually, step-by-step なぜ効果があるのか(The Real Reason) LLMs are not great at juggling. LLMs are not great at juggling. LLMs are not great at juggling. . multiple goals simultaneously Ask for: “Analyse the requirements, propose features, estimate effort, prioritise, then write a plan”—and you’ve set up a multi-objective optimisation problem. The model will usually do a decent job on 客観的かつ静かに他者を差し上げる。 one Prompt Chainingは認知負荷を減らす: . one step → one output → one success criteria 3) Core Mechanism: Input → Process → Output(繰り返し) その中心に、Prompt Chainingはループです。 入力:前のステップ出力 + 新しいデータ Process: next prompt with rules + format constraints (プロセス:ルール+フォーマット制限を含む次のプロンプト) 出力:次のステップの構造化された結果 以下は、あなたが視覚化できる簡単なチェーンです。 flowchart LR A[Raw user feedback] --> B[Prompt 1: Extract pain points] B --> C[Prompt 2: Propose features] C --> D[Prompt 3: Prioritise & estimate effort] D --> E[Prompt 4: Write an iteration plan] 4) Four Non-Negotiables for Building Good Chains 4.1 Sub-tasks must be independent connected そして そして 独立:各ステップは1つの仕事を行う(重複しない) 接続:各ステップは以前の出力に依存します(「浮動」のステップはありません) 悪い:「痛みのポイントとデザインの特徴を抽出する」良い:ステップ1は痛みのポイントを抽出する;ステップ2はそれらに基づいて機能を設計します。 4.2 中間出力は構造化されなければならない Free text is fragile. The next prompt can misread it, re-interpret it, or ignore it. フリーテキストは脆弱です。 構造化された形式を用いて、例えば で、 , or . JSON tables bullet lists with fixed keys Example (JSON you can actually parse): { "pain_points": [ {"category": "performance", "description": "Checkout takes > 8 seconds", "mentions": 31}, {"category": "ux", "description": "Refund button hard to find", "mentions": 18}, {"category": "reliability", "description": "Payment fails with no error", "mentions": 12} ] } 4.3 各プロンプトは明示的に「相続」する必要があります。 モデルが「あなたが意味したことを覚えておく」と仮定しないでください. In the next prompt, explicitly refer to the previous output: 「pain_points JSON を使用して、pain_points で、項目ごとに 1 ~ 2 つの機能を生成します。 pain_points JSON を使用して、 「1~2個のアイテムを生成する」 pain_points 4.4 失敗パスで構築(検証 + 修理) すべてのチェーンには「品質のゲート」が必要です。 検証: 「出力には必要なすべてのキーが含まれていますか? 数字は一貫していますか?」 修理:「欠けている場合は、欠けている部品のみを再生する」 Guardrail: “Max 2 retries; otherwise return best effort + errors” 5)どこにでも使える3つのアーキテクチャ 5.1 Linear Chaining: fixed steps, no branches ワークフローは予測可能。 Use it when: Example: UK Monthly Revenue Report (Linear) たとえば、イギリスの電子商取引店からCSVの輸出を持っていて、以下のことを望んでいるとします。 清掃 洞察 a management-ready report Step 1 — Data cleaning prompt (outputs a clean table or JSON) SYSTEM: You are a data analyst. Follow the instructions exactly. USER: Clean the dataset below. Rules: 1) Drop rows where revenue_gbp or units_sold is null. 2) Flag outliers in revenue_gbp: > 3x category mean OR < 0.1x category mean. Do not delete them. 3) Add month_over_month_pct: (this_month - last_month) / last_month * 100. 4) Output as JSON array only. Each item must have: date, category, revenue_gbp, units_sold, region_uk, outlier_flag, month_over_month_pct Dataset: <PASTE DATA HERE> Step 2 — Insights prompt (outputs bullet insights) SYSTEM: You are a senior analyst writing for a UK leadership audience. USER: Using the cleaned JSON below, produce insights: 1) Category: Top 3 by revenue_gbp, and Top 3 by month_over_month_pct. Include contribution %. 2) Region: Top 2 regions by revenue, and biggest decline (>10%). 3) Trend: Overall trend (up/down/volatile). Explain revenue vs units relationship. Output format: - Category insights: 2-3 bullets - Region insights: 2-3 bullets - Trend insights: 2-3 bullets Cleaned JSON: <PASTE STEP-1 OUTPUT> Step 3 — Report-writing prompt (outputs final document) SYSTEM: You write crisp internal reports. USER: Turn the insights below into a "Monthly Revenue Brief" (800–1,000 words). Structure: 1) Executive summary (1 short paragraph) 2) Key insights (Category / Region / Trend) 3) Recommendations (2–3 actionable items) 4) Close (1 short paragraph) Use GBP (£) formatting and UK spelling. Insights: <PASTE STEP-2 OUTPUT> ラインチェーンは最善の方法で退屈である:彼らは予測可能で、自動化され、テストしやすい。 5.2 Branching Chaining: 分類に基づいてパスを選択する the next step depends on a decision (type, severity, intent). Use it when: 例:顧客メッセージの分類(ブランチング) ステップ1 メッセージを分類する: SYSTEM: You classify customer messages. Output only the label. USER: Classify this message as one of: - complaint - suggestion - question Output format: label: <one of the three> Message: "My order was charged but never arrived, and nobody replied to my emails. This is ridiculous." Then you branch: If complaint → イベント対応プランを作成する If → produce feasibility + roadmap slotting suggestion 質問→直接サポートの回答を生成する場合 訴訟手続き(例) SYSTEM: You are a customer ops manager. USER: Create a complaint handling plan for the message below. Include: 1) Problem statement 2) Actions: within 1 hour, within 24 hours, within 48 hours 3) Compensation suggestion (reasonable for UK e-commerce) Output in three sections with bullet points. Message: <PASTE MESSAGE> Branching chains are how you stop treating every input like the same problem. 5.3 Looping Chaining: repeat until you hit a stop condition. ストップ状態に到達するまで繰り返します。 多くの類似の項目を処理する必要があるか、またはリテラティブに出力を改良する必要がある。 Use it when: Example: Batch-generate product listings (Looping) Step 1 リストを項目ブロックに分割する: SYSTEM: You format product data. USER: Split the following product list into separate blocks. Output format (repeat for each item): [ITEM N] name: key_features: target_customer: price_gbp: Product list: <PASTE LIST> ステップ2は各ブロックを上回ります。 SYSTEM: You write high-converting product copy. USER: Write an e-commerce description for the product below. Requirements: - Hook headline ≤ 12 words - 3 feature bullets (≤ 18 words each) - 1 sentence: best for who - 1 sentence: why it's good value (use £) - 150–200 words total, UK English Product: <PASTE ITEM N> 連鎖の必要性 : hard stop rules N 項目を正確に処理するか、または 単語数が長すぎる場合に最大2回、または 検証が終了した場合の停止 そうでなければ、世界で最も高価な無限のループを作成します。 6) Practical “Don’t Shoot Yourself” Checklist Problem: intermediate format is messy → next prompt fails 非交渉可能な形式化 Fix: 以下のようなラインを追加する: 「JSONのみの出力」 “If you can’t comply, output: ERROR:FORMAT.” 問題:モデルは以前の詳細を忘れる 毎回「契約」を繰り返します。 Fix: “Use the pain_points array from previous output.” (以前の出力から pain_points array を使用する) 「追加カテゴリーを発明しないでください」 タイトル: Loops Never Converge 測定可能な制約値 + max retries を定義します。 Fix: 「Word count ≤200」 マックス・レトリス: 2 "If still fails, return best attempt + an error list" を返します。 問題:ブランド選択が間違っている improve classification rules + add a second check. Fix: Example: 苦情にはネガティブな感情と具体的な問題が含まれなければなりません。 不確実な場合、出力ラベル:質問(明確化が必要) 7)チェーニングをより痛みやすくするツール You can chain prompts manually (copy/paste works), but tooling helps once you go beyond a few steps. n8n / Make: API 呼び出しの連鎖、出力の保存、アラートを起動するための低コードワークフローツール。 LangChain / LangGraph: メモリ、分支、リトリ、ツール呼び出し、および州管理でチェーンを構築します。 Redis / Postgres:中間の結果を維持し、再開、監査、および繰り返しの呼び出しを避けることができます。 Google Docs:驚くほど初期段階の「循環中の人間」チェーニングに効果的です。 8)どのようにレベルアップするか Prompt Chaining becomes even more powerful when you combine it with: : add a retrieval step mid-chain (e.g., “fetch policy docs” before drafting a response) RAG : approve before risky actions (pricing changes, customer refunds, compliance replies) Human approval gates マルチモダルステップ: text → image brief → diagram generation → final doc Final Take Prompt Chaining は「more prompts」ではありません。 . workflow design あなたがプロンプトを契約、検証、および失敗経路のステップとして扱い始めるとき、あなたのLLMは混沌としたテキストジェネレーターのように振る舞うのをやめ、信頼できるチームメイトのように行動し始めます - 一度に1つのステーション。 一発のデモ以外の何でも作っているのなら、 . chain it