Intermediate5 min read42 of 52

Workflow

A fixed, predefined sequence of LLM-powered steps with deterministic control flow.

SPEC: Workflow

Definition

[Definition] In the context of LLMs, a workflow is a fixed, predefined sequence of steps where an LLM (and potentially other tools) follow a predetermined path to accomplish a task. Unlike agents (which dynamically decide their next action), workflows execute a set script — the control flow is hard-coded by the developer, not chosen by the model.

Workflow vs. Agent

AspectWorkflowAgent
Control flowFixed, predeterminedDynamic, model decides
FlexibilityLow (follows script)High (adapts to situation)
PredictabilityHighLower
ReliabilityHigh (no unexpected detours)Lower (can go off-script)
ComplexityLower to build/debugHigher to build/debug
Use caseWell-defined, repeatable tasksOpen-ended, exploratory tasks

Workflow Types

Sequential Workflow (Pipeline)

Steps execute in a fixed order, one after another:

Input → [Step 1: Extract] → [Step 2: Transform] → [Step 3: Generate] → Output

Example: Resume screener

  1. Extract key information from resume (LLM call)
  2. Match against job requirements (LLM call or rule)
  3. Generate screening decision + explanation (LLM call)

Parallel Workflow

Multiple LLM calls run simultaneously, results combined:

Input → [Step A] ─┐ Input → [Step B] ─┼─→ [Aggregator] → Output Input → [Step C] ─┘

Example: Multi-perspective analysis — run legal, financial, and technical review in parallel

Conditional / Branching Workflow

Route to different steps based on output:

Input → [Classifier LLM] → if "technical" → [Tech Handler] → if "billing" → [Billing Handler] → if "urgent" → [Escalation Handler]

Example: Customer support routing

Iterative / Loop Workflow

Repeat a step until a condition is met:

Input → [Generate Draft] → [Evaluate Draft] → if not good enough → [Refine] → ... → if good enough → Output

Example: Self-refinement loop, code generation with testing

Map-Reduce Workflow

Process many items in parallel, then synthesize:

Long Document → [Split into chunks] → [Summarize chunk 1] ─┐ → [Summarize chunk 2] ─┼→ [Final Summary] → [Summarize chunk N] ─┘

Example: Long document summarization, report generation over many sources

LLM Workflow Patterns

Prompt Chaining

[Key Insight] - Output of LLM call 1 becomes input to LLM call 2 - Each call handles one well-scoped sub-task - Improves reliability vs. one giant prompt

Validation / Gate Pattern

[Generate] → [Validate/Check] → if passes → output → if fails → [Fix] → [Validate again]

Enforces quality or format constraints

Fan-Out / Fan-In

  • Fan-out: one input → many parallel LLM calls
  • Fan-in: many results → one aggregator LLM call
  • Common for: ensemble reasoning, multi-source synthesis

Human-in-the-Loop

[LLM Step] → [Human Review] → approve/reject/edit → [Next LLM Step]

For high-stakes tasks requiring human oversight

Building Workflows: Frameworks

FrameworkApproach
LangChain (LCEL)Pipe operator chaining `chain1
LangGraphGraph-based workflow with state management
LlamaIndex WorkflowsEvent-driven workflow system
Prefect / AirflowGeneral-purpose workflow orchestration (not LLM-specific)
AWS Step FunctionsManaged state machine workflow
Claude Code WorkflowsJS-based agent orchestration scripts

Example: Document Processing Workflow

python
# Step 1: Extract entities
entities = llm.call("Extract all company names, dates, and amounts: " + document)

# Step 2: Validate extraction
is_valid = llm.call("Check if this extraction is complete: " + entities)

# Step 3: Conditional branch
if is_valid:
    # Step 4: Generate summary
    summary = llm.call("Summarize the key findings: " + entities)
    return summary
else:
    # Step 4b: Re-extract with guidance
    entities = llm.call("Re-extract more carefully, you missed some items: " + document)

Workflow Design Principles

  1. One task per LLM call — focused prompts outperform sprawling ones
  2. Validate between steps — catch errors early before they propagate
  3. Use structured outputs — JSON/schema enforces contracts between steps
  4. Log all LLM inputs/outputs — essential for debugging
  5. Handle failures explicitly — what happens when a step fails?
  6. Test each step independently — unit test each LLM call
  7. Monitor costs — workflows multiply API calls

When to Choose Workflows vs. Agents

Choose WorkflowChoose Agent
Task steps are known in advanceSteps unknown until runtime
Need predictable, auditable executionNeed flexible problem-solving
High reliability requiredFlexibility > reliability
Debugging/testing is priorityTask is exploratory
Compliance/regulated environmentResearch/experimental context

Related Concepts

  • Agent, Prompt Chaining, LangChain, LangGraph, Orchestration, Structured Output, Pipeline