Advanced·4 min read

Workflow

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

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

| Aspect | Workflow | Agent |

|--------|----------|-------|

| Control flow | Fixed, predetermined | Dynamic, model decides |

| Flexibility | Low (follows script) | High (adapts to situation) |

| Predictability | High | Lower |

| Reliability | High (no unexpected detours) | Lower (can go off-script) |

| Complexity | Lower to build/debug | Higher to build/debug |

| Use case | Well-defined, repeatable tasks | Open-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

  • 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

    | Framework | Approach |

    |-----------|---------|

    | LangChain (LCEL) | Pipe operator chaining chain1 | chain2 |

    | LangGraph | Graph-based workflow with state management |

    | LlamaIndex Workflows | Event-driven workflow system |

    | Prefect / Airflow | General-purpose workflow orchestration (not LLM-specific) |

    | AWS Step Functions | Managed state machine workflow |

    | Claude Code Workflows | JS-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 Workflow | Choose Agent |

    |----------------|-------------|

    | Task steps are known in advance | Steps unknown until runtime |

    | Need predictable, auditable execution | Need flexible problem-solving |

    | High reliability required | Flexibility > reliability |

    | Debugging/testing is priority | Task is exploratory |

    | Compliance/regulated environment | Research/experimental context |

    Related Concepts

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

Go Deeper With Live Instruction

This topic is covered in depth in our llm engineering program (Session 7).