Telnyx - Global Communications Platform ProviderHome
Voice AI AgentsText-to-SpeechSpeech-to-TextEmbeddingsSearch APIBrowser APIMeetingBotVoice DesignInference APIAgentSDKFunctionsStateful ActorsKVSQLDBStorageGlobal NumbersVoice APISIP TrunkingSMS APIEmail APIRCSWhatsAppWebRTCVerify APINumber ReputationNumber LookupDeepfake DetectionBranded CallingIoT SIMeSIMMobile VoicePrivate Wireless GatewaysVirtual Cross ConnectsCloud VPNGlobal IP200+ open-source buildsagent-signup.mdx402View all primitivesHealthcareFinanceTravel and HospitalityLogistics and TransportationContact CenterInsuranceRetail and E-CommerceSales and MarketingServices and DiningView all solutionsVoice AIVoice APIInferenceMobile VoiceSpeech-to-TextText-to-SpeechSIP TrunkingSMS APIEmail APIWhatsApp Business APIGlobal NumbersIoT SIM CardView all pricingOur NetworkGlobal communicationsEdge ComputeAgents PlatformPartnersCareersCustomer storiesResource centerMission Control PortalEventsVoice AI agent playbookSupport centerSETIDev DocsIntegrationsCode examplesBenchmarks
Contact salesLog in
Sign up
Contact salesLog in
Sign up
Start building

Social

Compare

  • Twilio
  • Bandwidth
  • Plivo
  • Vonage
  • Wasabi
  • Amazon S3
  • ElevenLabs
  • Vapi
  • Baseten
  • Together.ai
  • Amazon Connect
  • Lumen
  • Cloudflare
  • Resend
  • SendGrid
  • Mailgun

Resources

  • Release Notes
  • Acceptable Use
  • Terms and conditions
  • Website Terms and Conditions
  • Data and Privacy
  • Report Abuse
  • Privacy Policy
  • Cookie Policy
  • Law Enforcement
  • Trust Center

Company

  • Why Telnyx
  • Our Network
  • Global Coverage
  • Customer Stories
  • Careers
  • Country Specific Requirements

Social

Company

  • Our Network
  • Global Coverage
  • Release Notes
  • Careers
  • Voice AI
  • AI Glossary
  • Shop

Legal

  • Data and Privacy
  • Report Abuse
  • Privacy Policy
  • Cookie Policy
  • Law Enforcement
  • Acceptable Use
  • Trust Center
  • Country Specific Requirements
  • Website Terms and Conditions
  • Terms and Conditions of Service

Compare

  • ElevenLabs
  • Vapi
  • Baseten
  • Together.ai
  • Twilio
  • Bandwidth
  • Vonage
  • Amazon Connect
  • Lumen
  • Cloudflare
  • Resend
  • SendGrid
  • Mailgun
Telnyx
© Telnyx LLC 2026
ISO • PCI • HIPAA • GDPR • SOC2 Type II

Ask AI

  • GPT
  • Claude
  • Perplexity
  • Gemini
  • Grok
Back to Glossary

What is prompt chaining in AI? How it works, with examples

Prompt chaining splits an LLM task into a sequence of prompts, each feeding the next. How it works, examples, and how it differs from chain-of-thought.

Emily Bowen
Editor: Emily Bowen

Updated October 2026

Prompt chaining is a technique for large language models (LLMs) that splits a task into a sequence of smaller prompts, where each prompt's output becomes part of the next prompt's input. Instead of one prompt that has to plan, write, and check its own work at once, a prompt chain gives each model call one job. Each result can be checked before it goes to the next prompt.

In a 2024 study of text summarization, researchers Sun and colleagues found that a chain of three prompts (draft, critique, refine) produced better summaries than one prompt that asked for all three steps.

What is prompt chaining?

This content was generated with the assistance of AI. Our AI prompt chain workflow is carefully grounded and preferences .gov and .edu citations when available. All content is reviewed by a Telnyx employee to ensure accuracy, relevance, and a high standard of quality.

Sign up and start building.

Sign UpContact Us

A prompt chain is a series of LLM calls in which code passes each call's output to the next. In an AI agent, by contrast, the model chooses its own next step as it runs.

The term chaining comes from human-computer interaction research. Researchers Wu, Terry, and Cai introduced it in AI Chains, a paper presented at the CHI 2022 conference. They described LLM steps linked so that the output of one step becomes the input for the next.

Outside that research, prompt chaining also goes by chain prompting and LLM chaining.

The word chaining has an older meaning in AI, unrelated to prompts. Forward and backward chaining are the ways a rule-based inference engine applies if-then rules to facts.

How does prompt chaining work?

A prompt chain works through handoffs and gates between its model calls. In a handoff, code inserts one call's output into the next call's prompt.

In a gate, code checks that output before passing it on. Anthropic's guide to building agents uses the same word for these programmatic checks.

A chain that turns a support call transcript into a follow-up email shows each step in order:

  • The extract step sends the transcript to the model with a prompt that asks for JSON: the customer's name, the issue, and a list of promised actions with their follow-up dates.
  • A gate in code parses the JSON and confirms that the name, the issue, and at least one promised action are present. On a failure, the extract step runs once more with the missing fields named in its prompt. A second failure goes to a person.
  • An optional review step catches what code can't. A second call reads the transcript and the fields side by side and flags any promise or date the fields missed. A flag sends the transcript back through the extract step under the same one-retry rule.
  • The write step sends only the checked fields, not the full transcript, with a prompt that asks for the email.
  • A final review call compares the email with the fields and flags any promised action or date the email dropped or changed. A flagged email goes back to the write step once, then to a person.

A prompt chain for a support call in five steps. Model calls extract JSON fields from the transcript, optionally review the fields against the transcript, write the follow-up email from the checked fields, and run a final review. Between extract and review, a code gate checks the JSON and retries once before sending a failure to a person. Code sets the order and runs the gates, and the model does the work in each step.

Each step sees only what it needs. The write step works from checked fields instead of the raw transcript, so it has no transcript to misread. An extraction that fails stops at a check instead of reaching the customer.

In Python, the extract step, its gate with one retry, and the write step take about 30 lines:

Python
123456789101112131415161718192021222324252627282930
import jsonREQUIRED = ("customer_name", "issue", "promised_actions")def ask(prompt): # One model call. client is any OpenAI-compatible chat client. reply = client.chat.completions.create( model=MODEL, messages=[{"role": "user", "content": prompt}]

Prompt chaining examples

A common prompt chaining example is draft, review, refine: one call writes a draft, a second reviews it against stated criteria, and a third revises it using that review.

Anthropic's Claude prompting guide names this self-correction chain as the most common chaining pattern.

Other chains follow the same rule of one job per call:

  • In an outline chain, one call drafts an outline and a check compares it against criteria such as required sections. A third call writes the document from the approved outline, the same way a content brief becomes a first draft.
  • In a translation chain, one call writes marketing copy and a second translates it, so each prompt carries instructions for one skill.
  • In a document question chain, one call pulls out the passages that bear on a question. A second call answers from those passages alone, so the answer is easy to check against the text.

Types of prompt chains

Prompt chains come in four shapes: sequential, branching, parallel, and looping. In all four, every possible path is set in code before the chain runs.

  • A sequential chain passes each call's output to the next in a fixed order. The support call chain is sequential, with a loop through its review step.
  • A branching chain has one call classify the input, and code sends it down one of several paths. Anthropic's agents guide gives the example of customer service queries split into general questions, refund requests, and technical support, each with its own prompts and tools.
  • A parallel chain runs independent calls at the same time, and code merges their outputs. One call can answer a user while another screens the same request for inappropriate content.
  • A looping chain repeats a step until a check passes, as when the support call chain's review step sends a missed date back to the extract step.

Four shapes of prompt chain. Sequential passes each call's output to the next in a fixed order. Branching has one call classify the input and code route it to general question, refund, or technical support. Parallel runs two calls at once, answering a user and screening the request, and code merges their outputs. Looping repeats a step until a check passes, sending a missed date back to extract. Every possible path is set in code before the chain runs.

Anthropic's guide reserves the name prompt chaining for the sequential shape and calls the other three routing, parallelization, and evaluator-optimizer.

A model can choose among those paths, as the classify call does, but can't add a new one. That is the line between a chain and an agent.

How to build a prompt chain

Building a prompt chain starts with choosing where to split. Good split points are places where a step's output can be checked in code, or where the next step needs only a small part of the input. Seven practices keep a chain reliable:

  • Each call does one job. A step that both extracts and writes has two ways to fail and only one output to inspect.
  • Handoffs use a structured format, such as JSON or labeled sections, that the gate and the next prompt can both parse. In a study of PromptChainer, a visual tool for building chains, Wu and colleagues found that people needed careful scaffolding to reshape each step's output into the next step's input.
  • Gates check what code can check: valid JSON, required fields, length limits, values from a known list. A model-based review handles the judgment calls, such as tone or whether a summary dropped a key fact.
  • Each step gets its own tests, with fixed inputs and expected outputs, like a function.
  • Every intermediate output goes to a log, so a wrong final result can be traced to the first step that went wrong.
  • Each step gets the model it needs. A simple extraction or classification step is a candidate for a smaller, faster model. That step's tests show whether the smaller model holds up.
  • Sequential calls add up. A chain of five sequential steps waits on five model responses. Steps that don't depend on each other can run in parallel instead.

Prompt chaining vs a single prompt

A single prompt is the better choice when one model call can do the task reliably. A prompt chain earns its extra calls when the task has distinct steps that fail in different ways or need checking along the way.

Anthropic's agents guide describes the same trade: a chain gives up some latency for accuracy by making each call an easier task. It also notes that for many applications a single well-built call, with retrieval and in-context examples, is enough.

Scoring a single prompt field by field on a labeled set of real inputs shows whether it needs a chain. If its failures cluster in one step, such as dropped dates, that step is the place to split.

The strongest single-prompt alternative asks for the fields and the email together as one JSON object, then validates it in code. That design gets a check without a second call. A failed check reruns the whole job, where a chain retries only the step that failed.

A chain gives a developer four things a single prompt can't:

  • an output to inspect at every step
  • a check in code between steps
  • a different model or setting for each step
  • steps that can be reused in other chains

A chain's tokens are the sum of each call's input and output. Its latency is the sum of its sequential calls, plus any retries.

Latency matters only when someone waits on the result. No one waits on a follow-up email, but a voice reply has a caller on the line.

Errors compound across steps in either design. If each of four sub-steps is right 95% of the time and failures are independent, all four are right only about 81% of the time (0.95 multiplied by itself four times).

A single prompt gives no place to catch the failed step. A chain's gates catch the failures code can detect, such as a missing field, and retry that step with the problem named.

A single prompt also degrades as it grows. Telnyx's guide to voice AI prompts describes a prompt that keeps absorbing edge cases until it becomes hard to test. Splitting it into steps is one way out.

Prompt chaining vs chain-of-thought prompting and AI agents

The difference between prompt chaining, chain-of-thought prompting, and an AI agent is who decides the next step: the developer's code, the model inside a single response, or the model at run time.

Prompt chaining vs chain-of-thought prompting

Prompt chaining splits a task across several model calls. Chain-of-thought prompting keeps the task in one call and asks the model to write out its reasoning steps before it answers.

The difference is where a mistake can be caught. A chain has a join between steps where code can check the output. Chain-of-thought reasoning happens inside one response, so nothing outside the model can stop a wrong step.

Chain-of-thought works on its own for reasoning that fits in one answer.

Any step in a chain can also use chain-of-thought prompting, or a reasoning model that writes its chain of thought on its own. Providers bill those hidden reasoning tokens at output rates, as Telnyx's guide to LLM APIs notes.

Prompt chaining vs AI agents

A prompt chain follows a plan written in code. An AI agent lets the model make the plan as it goes.

An agent built on the ReAct pattern, for example, alternates reasoning with actions such as a search. It picks each next action from what the last one returned.

A chain fits a task whose steps are known ahead of time. An agent fits a task whose steps depend on what the model finds.

Orchestrator-workers falls between a chain and an agent: a central model splits the task at run time and hands the pieces to worker models. Several models working together this way form a multi-agent system.

A comparison of prompt chaining, chain-of-thought prompting, and an AI agent by who decides the next step. In prompt chaining the developer's code decides, across several model calls in a plan written in code, such as draft, review, refine, for tasks whose steps are known ahead of time. In chain-of-thought the model decides inside one response, writing out its reasoning before it answers. In an AI agent the model decides at run time and makes the plan as it goes, as ReAct alternates reasoning with actions such as a search.

Prompt chaining in voice AI agents

A prompt chain in a voice AI agent keeps one model call inside each conversation turn and moves its other steps before or after the reply. Every extra call inside the turn is silence the caller hears.

The turn already spends time on transcription, the model, and speech, which Telnyx's guide to orchestration tools counts as one latency budget.

A chain's steps can run in three places:

  • Before the reply, routing on facts the system already has, such as whether the account is verified, runs in plain code with no model call.
  • During the reply, one model call answers the caller and picks where the conversation goes next.
  • After the call, summaries, tickets, and CRM updates run once the caller hangs up.

Telnyx voice AI agents follow this pattern through conversation workflows, which split a call into steps, each with its own instructions and, where it helps, a faster model.

After the call, post-conversation processing gives the assistant one more model turn for wrap-up work. It is in beta.

Teams that build their own chain can run it on the Voice API, which handles call control and streams the call's audio to their own pipeline.

Frequently asked questions

What is prompt chaining in Claude?

Prompt chaining in Claude means splitting a task into separate Claude API calls, with each call's output passed into the next. Anthropic's standard example is a draft, review, and refine chain.

Anthropic's prompting guide says Claude now handles most multistep reasoning within a single request. Explicit chaining is still useful, it adds, when a developer needs to inspect intermediate outputs or enforce a specific pipeline structure.

What is LLM chaining?

LLM chaining is another name for prompt chaining: connecting several large language model calls so that each call's output becomes input to the next.

An LLM chain can also mix model calls with other steps, such as a database lookup or a plain function. Researchers Khot and colleagues designed decomposed prompting so any sub-task prompt can be swapped for a trained model or a symbolic function.

How does prompt chaining work in LangChain?

LangChain builds a prompt chain by joining components with the pipe operator, as in prompt | model | parser. The result is a RunnableSequence, in which each component's output is the next one's input.

LangChain calls this composition style the LangChain Expression Language (LCEL). Its older chain classes, such as LLMChain, are deprecated and moved to the langchain-classic package in LangChain v1.

Telnyx Inference can fill the model slot through LangChain's ChatOpenAI class pointed at the Telnyx base URL.

What is the difference between forward and backward chaining in AI?

Forward chaining starts from known facts and applies every if-then rule whose conditions are met, adding each conclusion as a new fact until it reaches the goal. Backward chaining starts from the goal and works back to the facts that would prove it.

Both are inference methods for rule-based systems, described in Russell and Norvig's AI textbook. Neither involves prompts. Prompt chaining borrows only the word.

Is prompt chaining still useful with reasoning models?

Prompt chaining is still useful with reasoning models when a task needs checkpoints outside the model. A reasoning model works through a multistep problem inside one call.

A chain built only to make a model reason step by step may no longer be needed. A chain still adds what a single call can't: a code check between steps, a different model for each step, and intermediate outputs a developer can log and test.

Sources

  • Wu, Terry, and Cai. AI Chains: Transparent and controllable human-AI interaction by chaining large language model prompts. CHI 2022.
  • Wu, Jiang, Donsbach, Gray, Molina, Terry, and Cai. PromptChainer: Chaining large language model prompts through visual programming. CHI 2022 Extended Abstracts.
  • Sun, Yuan, Cao, Li, and Liu. Prompt chaining or stepwise prompt? Refinement in text summarization. Findings of the Association for Computational Linguistics, 2024.
  • Wei, Wang, Schuurmans, Bosma, Ichter, Xia, Chi, Le, and Zhou. Chain-of-thought prompting elicits reasoning in large language models. NeurIPS 2022.
  • Yao, Zhao, Yu, Du, Shafran, Narasimhan, and Cao. ReAct: Synergizing reasoning and acting in language models. ICLR 2023.
  • Khot, Trivedi, Finlayson, Fu, Richardson, Clark, and Sabharwal. Decomposed prompting: A modular approach for solving complex tasks. ICLR 2023.
  • Anthropic. Building effective agents. December 2024.
  • Anthropic. Chain complex prompts. Claude prompting documentation.
  • Russell and Norvig. Artificial Intelligence: A Modern Approach. Forward-chaining and backward-chaining algorithms.
  • LangChain. RunnableSequence, langchain-core reference, and the LangChain v1 migration guide.
  • Telnyx. Conversation workflows. Telnyx developer documentation.
  • Telnyx. Post-conversation processing. Telnyx developer documentation.
  • Telnyx. LangChain integration. Telnyx developer documentation.
Share on Social

Jump to:

What is prompt chaining?How does prompt chaining work?Prompt chaining examplesTypes of prompt chainsHow to build a prompt chainPrompt chaining vs a single promptPrompt chaining vs chain-of-thought prompting and AI agentsPrompt chaining in voice AI agentsFrequently asked questionsSources

Sign up for emails of our latest articles and news

)
return reply.choices[0].message.content
def extract(transcript, note=""):
raw = ask(note + "Return JSON with customer_name, issue, and promised_actions "
"(a list of {action, date}, with date as YYYY-MM-DD or null) "
"from this call transcript:\n" + transcript)
try:
fields = json.loads(raw)
except json.JSONDecodeError:
return None, ["valid JSON"]
return fields, [k for k in REQUIRED if not fields.get(k)]
# Extract, then gate: one retry that names what was missing, then a person
fields, missing = extract(transcript)
if missing:
fields, missing = extract(transcript, f"The last answer was missing {missing}. ")
if missing:
raise ValueError(f"Extraction failed twice ({missing}): send to a person")
# Write: draft the email from the checked fields only
email = ask("Write a short follow-up email using only these facts:\n" + json.dumps(fields))