Skip to the page
Tecyfy

Prompting interview question · easy

Explain how prompt chaining works and provide an example of when it might be useful.

The short answerPrompt chaining splits a task into a sequence of smaller prompts, where the output of one step becomes input to the next, often with code in between that checks or transforms the results.

The full answer

Prompt chaining splits a task into a sequence of smaller prompts, where the output of one step becomes input to the next, often with code in between that checks or transforms the results. Each prompt does one job well, and you can test, debug and improve each step on its own.

How it works

  1. Decompose the task into stages with clear inputs and outputs.
  2. Write a focused prompt for each stage.
  3. Pass outputs forward, ideally in structured form (JSON or tagged sections) so code can validate them.
  4. Add checks between steps: does the extraction have every field, does the generated SQL parse?
  5. Branch or loop where needed: route to different prompts by category, or send a draft back for revision if a check fails.

Example: answering questions about a long contract

Step 1  Extract: "From the contract below, quote every clause about
        termination, notice periods and penalties, with section numbers."
            ↓ (quotes as a list)
Step 2  Answer: "Using only these quotes, answer the question:
        Can the customer cancel early, and what would it cost?"
            ↓ (answer with section references)
Step 3  Check: "Does each statement in this answer follow from the quotes?
        List any that don't."

Splitting extraction from answering keeps the answer grounded, and the check step catches unsupported claims before a person sees them.

When chaining is useful

  • Multi-stage work: research, then outline, then draft, then edit.
  • Different skills per step: classify a support ticket, then use the prompt for that category.
  • Data pipelines: extract fields from a document, validate them in code, then generate a summary.
  • Quality control: generate, then critique, then revise.
  • Long inputs: summarise each chapter, then combine the summaries.
  • Mixing models: a small, fast model for simple steps and a stronger one for hard reasoning, which cuts cost.

Advantages

  • Easier to debug: you can see which step failed.
  • More reliable: each prompt is simpler.
  • Reusable steps across workflows.
  • Checks in code between steps.

Drawbacks

  • More calls mean more latency and some extra cost.
  • Errors early in the chain carry forward, so validate between steps.
  • Steps lose context the earlier ones had unless you pass it on.

Chaining and agents In a chain, the developer fixes the sequence. In an agent, the model decides the next step and which tools to call. Fixed chains are more predictable and easier to test, so use them when the steps are known in advance, and agents when they aren't.

Last updated 16 October 2026