# What is prompt chaining? multi-step LLM guide

What is prompt chaining and how does it sequence LLM calls for complex tasks? Definition, patterns, and practical workflow examples for AI builders.


## What is prompt chaining?

Prompt chaining is a design pattern where the output of one LLM call becomes the input to the next, creating a multi-step workflow that accomplishes tasks too complex for a single prompt. Instead of asking a model to research a topic, analyze findings, write a report, and format it for email — all in one shot — you break the job into discrete steps.

Prompt chaining is a core pattern in production AI automation.

Related: what is tool use in llms, [what is model context protocol](/blog/what-is-model-context-protocol), [best llm orchestration frameworks](/blog/best-llm-orchestration-frameworks), langchain vs llamaindex, [AI workflow tools](/blog/ai-workflow-tools), [CodeWords integrations](/integrations), [CodeWords templates](/templates).

## Why prompt chaining matters

A single LLM call has limits. Context windows cap how much data the model processes. Complex instructions get partially followed. Quality degrades when you overload a prompt with multiple objectives. [Anthropic's guide to building effective agents](https://www.anthropic.com/engineering/building-effective-agents) identifies prompt chaining as one of the foundational patterns for reliable AI systems.

Prompt chaining matters because:

-   **Quality improves**: Each step has a narrow, clear objective. The model performs better on focused tasks
-   **Debugging is easier**: When the final output is wrong, you can inspect each step's input and output to find where the chain broke
-   **Models can be mixed**: Use a cheap, fast model for classification and a powerful model for generation
-   **Token costs drop**: Smaller, focused prompts use fewer tokens per call

## How prompt chaining works

A basic prompt chain has three elements:

**Steps**: Each step is a single LLM call with a specific instruction. "Classify this support ticket by urgency." "Extract the customer name and issue description." "Draft a response appropriate for the urgency level."

**Data passing**: The output of step N becomes input to step N+1. Reliable chains use structured outputs (Pydantic models, JSON schemas) to reduce parsing errors between steps.

**Control flow**: Simple chains are linear. Advanced chains include branching (different prompts based on classification results), loops (re-run a step if quality checks fail), and parallelism.

## Common prompt chaining patterns

**Extract-then-act**: Extract structured data from unstructured input, then use the structured data to drive actions.

**Classify-then-route**: Classify incoming data into categories, then route each category to a specialized prompt.

**Generate-then-validate**: Generate content, then use a second LLM call to check the content against criteria.

**Summarize-then-synthesize**: Summarize multiple documents individually, then combine the summaries into a coherent synthesis.

## Prompt chaining in CodeWords

[CodeWords](https://codewords.agemo.ai) makes prompt chaining operational. Instead of manually wiring LLM calls in Python, describe your multi-step workflow to Cody and get a deployed service that chains calls with proper error handling, structured outputs, and external tool access.

Built-in access to OpenAI, Anthropic, and Gemini means you can use different models for different steps without managing multiple API keys. State persistence via Redis handles chains that span multiple runs. [3,000+ integrations](/integrations) connect chain steps to external data and services. Explore [templates](/templates) or check [pricing](/pricing).

