Step-by-Step Prompting

By the Syncfusion DevTutorials team · Last updated

Break big tasks into steps: numbered steps in one prompt, showing each result, prompt chaining with checks between steps, planning a chain, and the game play pattern.

"Read these 20 customer reviews, find the main problems, rank them, and write a short report for the team." That is four jobs in one sentence. A small model will often do one of them well and rush through the rest.

Big tasks go better when you do them in steps. You can list the steps inside one prompt. Or you can split the work into several prompts, where each answer is passed on to the next prompt. This lesson covers both ways. It also shows a fun way to learn: turning a prompt into a game.

The main idea: break a big task into small, clear steps. The model can do small steps well, and you can check them easily.

A Real-World Example

Think about cooking a meal from a recipe.

  • The recipe doesn't just say "Make lasagne". It says: boil the pasta, make the sauce, put them in layers, and then bake.
  • Each step is simple, and you can check each one. Is the pasta soft? Is the sauce thick?
  • If something goes wrong, you know which step to fix.

A step-by-step prompt is like a recipe for the model. A prompt chain goes further: each step is cooked on its own, and you check it before you move on.

What You Will Learn

In this lesson, you will learn:

  1. How to write numbered steps inside one prompt.
  2. How to ask the model to show the result of each step.
  3. What prompt chaining is, and when to use it.
  4. How to check each step before you pass it on.
  5. How to plan a chain for a real task.
  6. The game play pattern, for learning and practice.

The Compare tab in the Prompt sandbox lets you run a one-line request and a step-by-step version side by side. The Chat tab is good for the game play pattern, because a game takes several turns.

Steps Inside One Prompt

The simplest way is to number the steps in the prompt itself. The model then works through them in order.

Turn a task into numbered steps

function withSteps(task, steps, input) {
  const list = steps.map((s, i) => i + 1 + ". " + s).join("\n");
  return task + "\nFollow these steps:\n" + list + "\n\nInput:\n" + input;
}

console.log(withSteps(
  "Write a short bug report from the customer message.",
  ["Find the product and the feature.", "Find what went wrong.", "Guess the severity: low, medium or high.", "Write a 2-line report using steps 1 to 3."],
  "When I export 10,000 rows to Excel, the grid freezes and crashes."
));

Expected output:

Write a short bug report from the customer message.
Follow these steps:
1. Find the product and the feature.
2. Find what went wrong.
3. Guess the severity: low, medium or high.
4. Write a 2-line report using steps 1 to 3.

Input:
When I export 10,000 rows to Excel, the grid freezes and crashes.

Each step is one small job. The last step uses the earlier steps, so nothing gets skipped.

Compare it with a one-line request:

Prompt B asks the model to show the result of each step. Now you can see which step went wrong, not just the final report.

Easy Way to Remember: if you can't check a step, you can't fix it. Ask the model to label the result of each step, so you can see the work.

Prompt Chaining

Prompt chaining means splitting a task into several separate prompts. The output of one prompt becomes the input of the next prompt.

A prompt chain: each prompt does one job. Its output is checked, and then passed into the next prompt.

A chain is better than one big prompt when:

  • A step needs its own instructions, like a different role or format.
  • You want to check a step with code before you go on.
  • The input is long, and each step only needs part of it.
  • The model is small, and works better with one job at a time.

The next box shows how a chain connects: the template for step 2 is filled in with the output of step 1. The output of step 1 here is a sample text written for this example.

Pass one step's output into the next prompt

const step1Template = "List the problems in these reviews, one per line, no numbers.\n<reviews>\n{{reviews}}\n</reviews>";
const step2Template = "Group these problems into themes and count each theme.\n<problems>\n{{problems}}\n</problems>";

const reviews = "Export is slow.\nExport crashed twice.\nDocs are unclear.";
const step1Prompt = step1Template.replace("{{reviews}}", reviews);

// Sample output for step 1 (in an app, this comes from the model):
const step1Output = "Slow export\nExport crashes\nUnclear docs";
const step2Prompt = step2Template.replace("{{problems}}", step1Output);

console.log(step2Prompt);

Expected output:

Group these problems into themes and count each theme.
<problems>
Slow export
Export crashes
Unclear docs
</problems>

Each prompt is short, and does one job. Step 2 never sees the original reviews. It only sees the clean list from step 1.

Check Each Step

The big advantage of a chain is that you can check each output with code before you pass it on. If a check fails, stop the chain, or run that step again. This stops a bad result from spreading.

A gate between steps

function checkProblemList(text) {
  const lines = text.split("\n").map((l) => l.trim()).filter(Boolean);
  if (lines.length === 0) return "empty list";
  if (lines.some((l) => /^\d+[.)]/.test(l))) return "has numbers, but the prompt said no numbers";
  if (lines.some((l) => l.split(" ").length > 8)) return "a line is too long to be one problem";
  return "ok";
}

console.log(checkProblemList("Slow export\nExport crashes\nUnclear docs"));
console.log(checkProblemList("1. Slow export\n2. Export crashes"));
console.log(checkProblemList(""));

Expected output:

ok
has numbers, but the prompt said no numbers
empty list

Only the first output would move on to step 2. The other two would be run again, or marked as a problem.

Plan a Chain

Before you write the prompts, plan the chain on paper. Write down the steps, what each step needs, and what each step gives back. The next box writes a plan, and checks that each step's input comes from an earlier step.

Check that a chain plan is connected

const plan = [
  { step: "Extract problems", needs: ["reviews"], gives: "problems" },
  { step: "Group into themes", needs: ["problems"], gives: "themes" },
  { step: "Write the report", needs: ["themes", "audience"], gives: "report" },
];

const available = new Set(["reviews", "audience"]);
for (const s of plan) {
  const missing = s.needs.filter((n) => !available.has(n));
  console.log(s.step + ":", missing.length ? "missing " + missing.join(", ") : "ok");
  available.add(s.gives);
}

Expected output:

Extract problems: ok
Group into themes: ok
Write the report: ok

If you swapped the first two steps, "Group into themes" would show missing problems. A plan like this finds a broken chain before you spend any calls to the model.

The Game Play Pattern

The game play pattern turns a prompt into a game, with rules, turns, and a score. It is a great way to learn or practise with a model:

  • A quiz: the model asks one question at a time, and waits for your answer.
  • A role-play: the model plays a customer, and you practise replying.
  • A puzzle: the model gives clues, and you guess the answer.

A good game prompt sets the goal, the rules, one turn at a time, and how the game ends.

Build a game play prompt

function gamePrompt(g) {
  return [
    "Let's play a game. Goal: " + g.goal,
    "Rules:",
    ...g.rules.map((r) => "- " + r),
    "Ask only one question per turn, then wait for my answer.",
    "End after " + g.rounds + " rounds and give my score out of " + g.rounds + ".",
  ].join("\n");
}

console.log(gamePrompt({
  goal: "test my JavaScript basics.",
  rules: ["Ask about variables, loops and functions.", "After each answer, say correct or not and explain in one sentence."],
  rounds: 3,
}));

Expected output:

Let's play a game. Goal: test my JavaScript basics.
Rules:
- Ask about variables, loops and functions.
- After each answer, say correct or not and explain in one sentence.
Ask only one question per turn, then wait for my answer.
End after 3 rounds and give my score out of 3.

Play it in the Chat tab. Answer each question, and see if the model follows the rules and keeps the score.

Small models often lose track of a long game. They ask two questions at once, or forget the score. Keep games short. If the model starts to forget a rule, repeat it. Press Clear chat to start again. A score from a model is not a real grade.

Common mistakes

MistakeWrong ideaCorrect ideaWhat goes wrong
Many jobs in one line"The model will do all of it."Number the steps, with one job in each.Some jobs get skipped or rushed.
Hidden steps"I only need the final answer."Ask for the result of each step.You can't see where it went wrong.
No checks in a chain"Each step will be fine."Check each output before the next step.One bad output spoils every step after it.
Passing everything along"Give every step the full input."Pass on only what each step needs.The prompts get long, cost more, and confuse the model.
Too many steps"More steps are always better."Split a task only where it improves the result or helps you check it.Chains become slow and expensive for simple tasks.
Long games on small models"It will remember the rules for 20 rounds."Keep games short, and repeat the rules.The game goes off track, and the score is wrong.

Exercises

In each exercise, the last line should give back a value. Press Check to compare your value with the expected answer.

What to Remember

  • Break big tasks into small, numbered steps, with one job in each.
  • Ask the model to show the result of each step, so you can check it.
  • Prompt chaining splits a task into several prompts. Each output is passed on to the next prompt.
  • Check each step with code before you pass it on.
  • Plan what goes into and comes out of each step first.
  • The game play pattern sets a goal, rules, turns, and an end. Keep games short.

Next: Chain of Thought Prompting, where you ask the model to think through a problem before it answers.