Prompt Engineering — talk to AI like a pro — 5. Templates & debugging

18 min read min de lecture
Chapter 05

Templates & debugging

Chapter 5 of 10 · 50%

Chapter objectives

  • Capitalize on your best prompts as templates
  • Methodically diagnose a prompt that gives a bad result
  • Build a reusable library that improves over time

The problem of perpetually starting over

Let's do the math with Sofia. Every week, she writes: three LinkedIn posts, two newsletters, a dozen replies to customer reviews, email rewrites. For each of these tasks, she reinvents her prompt every time — from memory, with unintended variations, and up-and-down results. The good prompts she wrote last month? Lost in the conversation history.

This is the final level of this course, and the most profitable one: moving from craftsmanship (rewriting every time) to tooling (capitalizing on what works). The previous four chapters taught you to write a good prompt; this one teaches you to never rewrite it again.

Identifying your winning prompts

When a prompt gives an excellent result, the reflex to install immediately: save it. Not mentally — in a dedicated note. Then identify what in this prompt is permanent (the role, the tone, the constraints, the structure) and what is variable (the topic of the day, the text to process, the target length). Replace the variable parts with {{ }} fields: you've just created a template.

PROMPT
[TEMPLATE — Email rewrite]
You are {{role}}.
Rewrite this email so it is {{goal: shorter / warmer / firmer}}:
{{email}}
Constraints: max {{n}} words, {{tone}} tone.

Notice the writing convention: the {{goal}} field lists its usual values right in the template. In three weeks, you'll have forgotten what you used to put in that field — the template reminds you. A good template is self-sufficient: any colleague should be able to fill it in without asking you a question.

Anatomy of a robust template

Everything you've learned in this course converges here. A robust template contains: a role with an audience (chapter 4), a permanent context block about your company and your target (chapter 1), the task with its variable fields, few-shot examples if the format is specific (chapter 2), the constraints and the output format (chapters 1 and 4), and if the task is analytical, the reasoning guidance with an "Answer:" line (chapter 3).

PROMPT
[TEMPLATE — Product LinkedIn post]
You are a B2B communications manager writing for rushed, not very tech-savvy restaurant owners. Tone: direct, concrete, never corporate.

Examples of our style:
{{2 existing posts you're proud of}}

Task: write a LinkedIn post about {{topic}}, angle {{angle: time saved / testimonial / key figure}}.

Constraints: 80-120 words, opening hook as a question, 1 quantified benefit, final call to action, no exclamation marks, no hashtags.

This template encapsulates hours of past iterations. That's the capitalization effect: every improvement found once benefits all future uses. After three months, your templates encode an expertise that neither you nor your colleagues need to retrieve from memory anymore.

A template is never finished: with each use, if you improve a phrasing, carry the improvement back into the template. Otherwise, the saved version goes stale while your mental version improves.

Building your library (and keeping it alive)

Three or four templates require no organization. But at fifteen, you need a library: a note or document per project, with for each template a clear, task-oriented name ("Email rewrite — soften", not "prompt 7"), the template itself, an example of a successful output below it (to check at a glance that it's the right one), and the date of last update.

Where to store it? Where you already work: a Notion or Obsidian note, a shared doc, even a plain text file. The tool matters little; the routine matters: every Friday, two minutes to carry the week's good prompts into the library. Sofia also turned her three most-used templates into custom "GPTs" — the template becomes the system prompt (chapter 1), and all that's left day-to-day is filling in the fields.

Team bonus: a shared library aligns everyone. When Sofia's intern writes a post with the in-house template, he produces the brand tone from his very first day — Sofia's prompting expertise has become a team asset, not knowledge in her head.

Debugging a bad result: the method

Even with good tooling, a prompt will regularly disappoint you. The amateur reflex: rewriting everything at random, or worse, rerunning the same prompt hoping for a miracle. The pro reflex: diagnose before modifying, by reviewing the ingredients in order:

  • Missing context? → add who you are and the situation.
  • Ambiguous task? → specify the expected action.
  • Unspecified format? → impose length and structure.
  • No example? → add 1-2 examples (few-shot).

80% of bad prompts are missing just one of these elements. Add the missing ingredient instead of starting from scratch — and change only one thing at a time. If you modify three elements at once and it improves, you don't know which one did the work, and your library learns nothing. Prompt debugging follows the same hygiene as code debugging: one hypothesis, one change, one test.

flowchart TD
  B["Bad result"] --> Q1{"Missing context?"}
  Q1 -->|"Yes"| F1["Add who you are + the situation"]
  Q1 -->|"No"| Q2{"Ambiguous task?"}
  Q2 -->|"Yes"| F2["Specify the expected action"]
  Q2 -->|"No"| Q3{"Missing format?"}
  Q3 -->|"Yes"| F3["Impose length + structure"]
  Q3 -->|"No"| F4["Add 1-2 few-shot examples"]
The prompt debugging tree: almost always, just one ingredient is missing.

An underused diagnostic technique: ask the model itself. "Here is my prompt and the output I got. The output is too generic: what in my prompt is missing or confusing?" The model is surprisingly good at spotting the ambiguities in your instructions — it's your first prompt reviewer, free and always available.

The pitfalls of the over-corrected prompt

Debugging has its opposite excess: the obese prompt. By adding an instruction after every disappointment, some prompts become walls of fifteen constraints — several of which contradict each other ("be exhaustive" + "maximum 100 words"; "warm tone" + "strictly factual"). Faced with contradictory instructions, the model arbitrates silently, and you lose control over what is actually applied.

Hygiene rule: with every added constraint, ask yourself whether an existing constraint becomes obsolete or contradictory. And periodically, do a clean pass: start again from the bare template (role + task + format) and only reintroduce the constraints whose absence visibly degrades the result. You'll be surprised how many accumulated instructions no longer served any purpose.

Keep a "prompts that work" note per project. It's your most profitable asset over time: every successful iteration adds to it, and your starting level rises week after week.
Test your critical templates like code: before adopting them, run 3-4 different inputs through them including an edge case. A template that only works on the easy case isn't a template, it's a lucky shot.

The final word: a skill that compounds

Let's recap Sofia's journey. Chapter 1: her prompts gained a skeleton (context, task, format). Chapter 2: her examples replaced her adjectives. Chapter 3: her calculations and analyses became verifiable. Chapter 4: her outputs respect a register and usable formats. Chapter 5: all of this is capitalized in a library that improves every week. Same model as on day one — results beyond comparison.

That's the true nature of prompt engineering: not a collection of magic tricks, but a skill of structured communication that compounds over time. Models will change; the ability to phrase a precise need, to show by example, to demand the verifiable and to capitalize on what works will remain your advantage. Your move.

🛠️ Your turn

Context

Sofia keeps rewriting the same types of prompts and is losing precious time: LinkedIn posts, replies to customer reviews, email rewrites. This week, she decides to tool up once and for all: turn her three most frequent tasks into templates, set up her library, and install the continuous-improvement routine. She also has a prompt that's been taunting her for days — a meeting summary that's systematically too long and off-topic — perfect for practicing methodical debugging.

Instructions

  1. List your 3 most frequent AI tasks from the past week.
  2. For the most frequent one, find your best prompt and turn it into a template: spot what's permanent, replace what's variable with annotated {{ }} fields.
  3. Integrate the course takeaways: role + audience, few-shot examples if the format is specific, verifiable constraints, output format.
  4. Test the template on 3 different inputs including an edge case; adjust until it holds on all three.
  5. Take a failing prompt and walk through the debugging tree: identify the missing ingredient, change ONE thing, re-test.
  6. Create your "prompts that work" note: clear name per template, example of a successful output, update date.
  7. Block 10 minutes in your calendar on Friday to carry over the week's good prompts — the routine matters more than the tool.
Hint — A template is just your best prompt with blanks to fill in. Start with ONE frequent task: the first template already pays for the effort.

In summary

  • Capitalize on your best prompts as templates with {{ }} fields annotated with their usual values.
  • A robust template brings together everything learned: role + audience, context, few-shot examples, constraints, output format.
  • A living library (clear names, output examples, updates) turns your expertise into a team asset.
  • Debugging = diagnosing the missing ingredient (context, task, format, example) — 80% of bad prompts are missing just one.
  • Change only one thing at a time, and ask the model itself to critique your prompt: it’s your first reviewer.
  • Beware of the obese prompt: accumulated constraints end up contradicting each other; do clean passes.
  • Test your templates on several inputs including an edge case before adopting them.
  • Prompt engineering is a structured communication skill that compounds over time — models come and go, it stays.

Quiz — check your understanding

1. How do you reuse an excellent prompt?

A parameterized template avoids rewriting everything and capitalizes on every improvement found.

2. What is a frequent cause of a bad prompt?

Most of the time, just one of the key elements is missing. Diagnose before rewriting everything.

3. Why change only one thing at a time when debugging?

Three simultaneous modifications that improve the result teach you nothing: you don't know which one acted.

4. What is the risk of the over-corrected "obese" prompt?

"Be exhaustive" + "max 100 words": faced with contradictions, the model decides without telling you. Do clean passes.

5. What should a good prompt library entry contain?

The output example lets you verify at a glance that you have the right template; the clear name makes it findable; the date reveals staleness.

6. How do you verify that a template is robust before adopting it?

A template that only works on the easy case is a lucky shot, not a tool. The edge case reveals its solidity.

Auteur(s)

R

REHOUMA Haythem

Haythem Rehouma est un ingénieur et architecte IA et cloud, formateur et enseignant technique, avec un profil orienté IA médicale, AWS, MLOps, LLM/RAG et vision par ordinateur.