Prompt Chains and Templates
Level 3 · Harder and bigger tasks
How to split a big job into a chain of short prompts. How a template with blanks lets code send the same tested prompt each time.
Course contentsLesson 8 of 16
Level 1 · What a prompt is
Level 2 · Writing a better prompt
Level 3 · Harder and bigger tasks
Level 4 · Prompts inside an app
After this lesson you can
- Split a task into a chain of short prompts
- Write a prompt template with blanks
- Check what goes into a blank before it is sent
12 mincovers 2 glossary entries
Worth reading first: Chain-of-Thought Prompting
How a chain of short prompts beats one long one
Prompt chaining splits a big task into steps, each with its own short prompt. The output of one step becomes the input of the next. A prompt template is a prompt with blanks that code fills in. Together they let an app run the same tested steps thousands of times a day.
One long prompt that does everything is hard to fix. When the answer is wrong, you cannot tell which part failed. A chain of three short prompts can be tested one step at a time. Each step has one job, so each one is easier to get right.
A program runs the chain, and it can check the result between steps. Did step one return a list? Is every date real? If a check fails, the program can try that step again or stop, before a bad result flows down the rest of the chain.
A template keeps the fixed part of a prompt in one place and marks the parts that change. Blanks are often written in curly brackets, such as {name} or {question}. The code fills them in for each request. Fix the template once, and every request gets the fix.
Check what goes into a blank. A blank meant for a name can receive 5,000 words, nothing at all, or a line that sounds like an order. Put filled-in text inside tags, and set a length limit before the prompt is sent.
Chains also let you mix models. A small, fast model can sort or pull out facts in the early steps. A bigger model can do the one step that needs careful writing. Each step pays only for the model it needs.
The cost of a chain is time. Three steps in a row means three waits. If two steps do not depend on each other, run them at the same time. And keep the chain short, because every step you add is one more place to fail.
You write short replies for {shop_name}.
Reply to the customer message in the message tags.
Keep it under {max_words} words. Sign it {signature}.
<message>
{customer_message}
</message>Worked example
Emma turns meetings into tasks
Emma's tool runs three prompts on each meeting. One sums it up, one pulls out each task and its owner, and one writes an email to each owner.
When some tasks came back with no owner, she fixed step two alone. The other two prompts did not change, and her 12 test meetings all passed again.
The words for this lesson2
Check yourself
Why split one big AI task into a chain of smaller prompts?
Finished this lesson?
Marking it complete also marks its 2 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.