{
  "id": "prompt-chaining",
  "title": "Prompt Chaining",
  "lang": "en",
  "source_lang": "en",
  "summary": "Prompt chaining decomposes a task into successive model calls, passing intermediate outputs between stages to build a controlled, inspectable workflow.",
  "category": "computer-science",
  "subcategory": "artificial-intelligence",
  "type": "concept",
  "aliases": [
    "Chained prompting",
    "Prompt pipelines"
  ],
  "generated_at": "2026-11-04",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/prompt-chaining/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/prompt-chaining/",
      "json": "https://aiwiki.page/zh/prompt-chaining.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "Prompt chaining is a technique for organizing work with a large language model into multiple connected steps, in which the output of one model call supplies input to a later call. Instead of asking a model to complete an entire task in a single response, a chain assigns narrower responsibilities to successive prompts, such as extracting facts, constructing an outline, drafting text, and checking the result. It combines prompt engineering with application-level coordination: software determines what each stage receives, how intermediate results are handled, and when execution proceeds or stops."
    },
    {
      "heading": "Operating principle",
      "text": "A prompt chain separates a task into stages with explicit dependencies. Each stage typically includes instructions, relevant input data, an expected output format, and criteria for accepting the result. The stages may use the same model, different models, or a mixture of model calls and conventional software operations.\n\nA simple linear chain can be represented as\n\n\\[y_i = M_i\\bigl(P_i(x, y_{i-1})\\bigr),\\]\n\nwhere \\(x\\) is the original input, \\(P_i\\) constructs the prompt for stage \\(i\\), \\(M_i\\) is the model used at that stage, and \\(y_i\\) is its output. For the first stage, the prompt is constructed without a preceding output. More general implementations pass selected earlier outputs or a shared state rather than only the immediately preceding result.\n\nA document-processing chain, for example, might:\n\n- Extract claims and supporting passages from a document.\n- Group those claims into themes.\n- Produce an outline based on the groups.\n- Draft a report using the outline and extracted evidence.\n- Check whether the report’s claims are supported by the supplied passages.\n\nThe application connecting these stages can reject malformed output, request a revision, or route a result to human review. A chain is therefore more than a sequence of prompts written on a page: its behavior depends on how information and execution are coordinated.\n\nPrompt chaining ordinarily takes place during inference. It does not, by itself, update model parameters or constitute fine-tuning."
    },
    {
      "heading": "Structure and orchestration",
      "text": "Intermediate representations\n\nThe information exchanged between stages may be prose, tables, code, labels, or structured records. A common implementation uses JSON objects with fields such as claims, evidence, and unresolved_questions.\n\nStructured outputs make some checks straightforward. Software can verify that a required field exists, that a value has the expected type, or that an identifier refers to an available document. These checks do not establish that the content is true. A correctly formatted record can still contain an unsupported claim or an incorrect interpretation.\n\nIntermediate representations also determine what later stages can know. Passing only a summary reduces input size but may discard qualifications, exceptions, or source details. Passing the full history preserves more information but increases processing cost and may introduce irrelevant material.\n\nControl flow\n\nAlthough “chain” suggests a linear sequence, related workflows often include branching, parallel processing, and bounded revision loops. A classifier may select one of several specialized prompts; independent sections may be processed through parallel computing before being combined; a validation failure may trigger another attempt.\n\nIn broad usage, these arrangements are sometimes called chains, although “workflow” or “graph” describes them more precisely. Their control flow may be fixed in software or selected dynamically from model outputs.\n\nAn application programming interface commonly connects the coordinating application to the model. The application maintains state, handles failures, and enforces execution limits. Model-generated instructions have operational effects only when the surrounding software interprets or executes them."
    },
    {
      "heading": "Relationship to other techniques",
      "text": "Chain-of-thought prompting\n\nPrompt chaining and chain-of-thought prompting are distinct. Chain-of-thought prompting elicits or encourages intermediate reasoning within a model response. Prompt chaining divides work across separate calls, with externally managed transitions.\n\nA chain can contain a reasoning-oriented stage, but it need not request explanatory reasoning at all. A pipeline that extracts names, standardizes their spelling, and formats a table is a prompt chain even if every intermediate response is a short structured record.\n\nRetrieval-augmented generation\n\nRetrieval-augmented generation supplies retrieved information to a model. It can be implemented as part of a chain: reformulate a question, retrieve documents, select relevant passages, and generate an answer.\n\nRetrieval is not required for prompt chaining, and a retrieval-augmented system need not contain several model calls. The concepts describe different aspects of system design: retrieval concerns access to external information, while chaining concerns the organization of dependent processing stages.\n\nConversational interaction\n\nA conversation contains multiple turns, but multiple turns alone do not establish a task decomposition. In ordinary dialogue, a user may decide what to ask next. In a prompt chain, the application usually defines at least part of the sequence and the handoff between stages.\n\nA chain may nevertheless include human approval or clarification. Conversely, a chat application may execute an entire chain internally before displaying one response.\n\nAI agents\n\nAn AI agent may select actions, tools, or subsequent tasks according to its current state. A fixed prompt chain usually has a more constrained execution path. The distinction is a continuum rather than a strict boundary: an agent can invoke predefined chains, and a chain can contain a model-driven routing step. Multiple prompts do not, on their own, make a system autonomous."
    },
    {
      "heading": "Common patterns and applications",
      "text": "Extraction and transformation. A model extracts structured information from unstructured material, after which another stage normalizes or reformats it. Conventional software may perform deterministic transformations between calls.\n\nPlanning and execution. One stage produces an outline or task breakdown, and later stages carry it out. This can separate organizational decisions from detailed generation, but a flawed plan can constrain every subsequent step.\n\nDrafting and revision. An initial response is checked against stated criteria and then revised. The checking stage may examine style, completeness, consistency, or evidential support. Its judgments remain fallible.\n\nHierarchical summarization. Long documents are divided into sections, each section is summarized, and those summaries are combined. This is useful when the source exceeds a model’s context window, but repeated summarization can progressively remove important details.\n\nCode generation and testing. A chain may generate code, run it in a controlled environment, collect test results, and request corrections. Executable tests provide evidence beyond a model’s own assessment, although passing a limited set of tests does not establish correctness for all inputs.\n\nQuestion answering and reporting. Separate stages can interpret a question, gather evidence, compose an answer, and check claim-to-source correspondence. Preserving source identifiers across these stages supports data lineage and inspection."
    },
    {
      "heading": "Benefits and trade-offs",
      "text": "Decomposition can reduce the number of competing instructions within each call. Separate prompts can also be tested and revised independently. Intermediate outputs make some failures easier to localize: an incorrect final report may originate in extraction, interpretation, or presentation rather than in an undifferentiated generation step.\n\nChaining can also allocate resources selectively. A relatively small model may handle simple classification, while a more capable model handles difficult synthesis. Deterministic operations such as arithmetic, database lookup, and format checking can remain outside the model.\n\nThese advantages are conditional. More stages introduce additional failure points, implementation work, and operational dependencies. A strong single-call solution may outperform a poorly decomposed chain, particularly when the task requires close integration of information that decomposition separates.\n\nSequential calls also increase latency because dependent stages cannot run simultaneously. Total usage includes the input and output processed at every stage; repeatedly passing the same source material can be expensive. Input length depends partly on tokenization, not simply on character or word counts."
    },
    {
      "heading": "Reliability and error propagation",
      "text": "A central limitation is error propagation. An early stage may omit a fact or invent a premise that later stages treat as authoritative. Repetition and polished rewriting can make the resulting error appear more credible without adding evidence.\n\nIn a simplified model with independent stage-success probabilities \\(p_i\\), where every stage must succeed, the probability of complete success is\n\n\\[P(\\text{success}) = \\prod_{i=1}^{n} p_i.\\]\n\nReal chains rarely satisfy these assumptions: errors may be correlated, some stages can recover from earlier mistakes, and not every intermediate error changes the final result. The expression nevertheless illustrates why adding stages does not automatically improve reliability.\n\nA model-based review stage is not an independent guarantee of correctness. Models can share the same knowledge gaps, accept plausible but false premises, or produce unsupported corrections. Chaining does not inherently eliminate hallucinations.\n\nEvaluation therefore distinguishes stage-level performance from end-to-end performance. Useful measures include extraction accuracy, evidence coverage, final-answer correctness, latency, cost, and the frequency of human intervention. Comparison with a single-call baseline helps establish whether the extra stages provide a measurable benefit. Evaluation examples should be kept separate from prompt development to reduce overfitting to a small collection of cases."
    },
    {
      "heading": "Security and operational constraints",
      "text": "Prompt chains can transmit untrusted content across several model calls. A malicious instruction embedded in a retrieved document may be copied into an intermediate summary and then influence a later stage. This is a form of prompt injection; transformation or summarization does not necessarily remove the threat.\n\nSecurity depends on the surrounding application, including access control, least-privilege tool permissions, and separation between untrusted data and authoritative instructions. Where a chain can execute generated code, a sandbox limits the resources and capabilities available to that execution.\n\nOperational records can improve debugging, but intermediate prompts and responses may contain sensitive information. Logging, retention, and access policies therefore affect data privacy as well as observability.\n\nRetries and revision loops introduce additional concerns. Without explicit limits, a workflow can repeatedly generate and reject outputs, increasing cost or delaying completion. When a chain performs external actions, such as creating records or sending messages, retry handling must also account for the possibility of duplicate effects."
    }
  ],
  "links": [
    "large-language-model",
    "prompt-engineering",
    "neural-network-inference",
    "fine-tuning",
    "parallel-computing",
    "control-flow",
    "application-programming-interface",
    "chain-of-thought-prompting",
    "retrieval-augmented-generation",
    "ai-agent",
    "context-window",
    "automatic-text-summarization",
    "data-lineage",
    "tokenization",
    "ai-hallucination",
    "overfitting",
    "prompt-injection",
    "access-control",
    "least-privilege",
    "sandbox-computer-security",
    "data-privacy"
  ],
  "sources": [],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}