The Art of the Prompt
Part of the free Generative AI course on LogicWiz, module: The Agent Awakens.
Episode 10: The Art of the Prompt
"The model is the engine. The prompt is the steering wheel — and most crashes are steering errors."
When "Please Be Concise" Isn't Enough
Anjali wants Nova to sort incoming articles into categories so the homepage can auto-organise itself. Simple, thought Arjun. He asked Nova:
"Categorise this article: 'Central bank holds interest rates steady amid inflation fears.'"
Nova replied:
"Great question! This article appears to touch on several themes. It's primarily about economics and monetary policy, though you could also file it under business or even politics depending on your taxonomy…"
Helpful to a human. Useless to a pipeline. The code downstream expected one clean word — Business — and got a paragraph. It crashed.
The model isn't broken. The instruction was. It's the intern problem: hand a sharp new hire a fuzzy task — "sort these out" — and they'll do a reasonable job their way, not yours. A vague prompt leaves the model to fill the gaps with its own guesses, and you get a different guess every time.
Steering the model precisely is a real skill, and it has a name: prompt engineering.
The Four Pillars of a Good Prompt
A prompt is the input you give the model to wake it up and tell it what to do. Prompt engineering is the discipline of writing that input well. Four pillars carry almost every good prompt:
{{visual:prompt-anatomy}}
- Context — set the stage. Give the model a role and a goal, the way you'd brief an actor on their character before the scene. Ask a model to "explain inflation" cold and you get a textbook; tell it "you're explaining to a 10-year-old" and you get a lemonade-stand story. Same model, different brief. For Nova: "You are a news desk editor. Your job is to file articles into exactly one section."
- Structure — organise the prompt so both the model and your teammates can parse it, like the labelled sections of a contract instead of one long ramble. Use clear headers, often written as Markdown or XML-like tags:
# Role,# Task,# Input,# Constraints. - Constraints — pin down the output: its format, length, tone, and how to handle edge cases. These are the bumper rails on the bowling lane. "Reply with one word." "Respond in JSON." "Max 200 words."
- Iterate — you rarely nail it first try. Draft, run it, read the output, refine — like tuning a guitar string by string. Prompting is a loop, not a lucky guess.
flowchart LR
D[Draft the prompt] --> E[Evaluate the output]
E --> R[Refine the wording]
R --> D
Give the model a role, a structured task, and hard constraints, and watch the rambling disappear:
{{visual:structured-prompt-walkthrough}}
{{cell:l10-structured-prompt}}
Constraints: From Stochastic to Reliable
Here's the pillar that matters most for building real products.
By default a model is stochastic — a bit random. Think of a jazz musician: ask them to play the same tune twice and you get two lovely, different takes. Wonderful on stage; a disaster if that tune is a fire alarm that has to sound identical every time. Ask a loose question twice and you may get two differently-shaped answers.
Constraints are how you trade improvisation for reliability. The most powerful one is fixing the output format.
{{visual:stochastic-vs-constrained}}
Tell the model "respond with only a JSON object with keys category and confidence," and its reply becomes something your code can json.loads and trust — every single time. (JSON is just a labelled container both people and code can read: {"category": "Business", "confidence": 0.9}.) That predictable shape is exactly what Nova's homepage pipeline needs to auto-file each story with no human in the loop.
{{visual:json-output-walkthrough}}
{{cell:l10-json-output}}
💡 Tip: Constraints do double duty. "Respond in JSON" fixes the shape; naming the exact keys (schema control) fixes the fields. The more precisely you describe the output, the less room the model has to improvise something your code can't handle.
⚠️ Warning: Pair tight constraints with a low
temperature. Structure tells the model what shape to produce; low temperature stops it from getting creative with that shape.
Prompting Styles: Showing vs. Telling
Sometimes instructions alone aren't enough — the fastest way to teach a model a pattern is to show it examples, exactly the way you'd hand a new hire two or three finished reports before asking them to write their own. How many examples you show has names:
{{visual:shot-spectrum}}
- Zero-shot — no examples, just the instruction. ("Classify this headline.")
- One-shot — one worked example to anchor the format.
- Few-shot — several examples that establish a clear pattern. The model copies the pattern you demonstrated.
Few-shot is remarkably powerful: a handful of input → output pairs can lock the model into exactly the behaviour you want — no fine-tuning, no extra training, just examples in the prompt.
{{visual:few-shot-walkthrough}}
{{cell:l10-few-shot}}
Making the Model Think Out Loud
For harder problems, one more technique helps: Chain of Thought. Instead of demanding an instant answer, you ask the model to reason through the steps first — literally "think step by step." It's the difference between a student who blurts a guess at a word problem and one who writes out the working: the second is far more likely to be right. Reasoning out loud dramatically improves accuracy on anything with real steps — maths, multi-stage decisions, tricky classifications.
{{visual:chain-of-thought}}
Adding those four words costs almost nothing and changes the answer. Try it on a problem the model gets wrong when rushed:
{{visual:cot-walkthrough}}
{{cell:l10-chain-of-thought}}
Two heavier cousins exist for the toughest cases:
- Self-Consistency — run the reasoning several times and take the answer that comes up most often. It's a panel of experts taking a majority vote instead of trusting one opinion.
- Tree of Thoughts — let the model branch into several lines of reasoning and explore them before committing, the way a chess player looks a few moves down each candidate line before choosing.
📌 Summary: Prompt engineering steers the model with four pillars — Context (role + goal), Structure (clear headers), Constraints (fixed output format/schema), and Iterate (draft → evaluate → refine). Show examples with zero/one/few-shot, and unlock reasoning with Chain of Thought. Tight constraints turn a stochastic model into a reliable component.
Think of an advanced prompt as coding in plain English: you're spelling out the exact logical steps you want the model to follow.
What Nova Learns Next
Nova can now be steered with surgical precision. But a perfectly-worded prompt still can't rescue her from two hard walls: she doesn't know anything that happened after her training, and she confidently makes things up when she's out of her depth.
Next episode, Arjun discovers why even the best prompt can't fix a model that has no live information and no memory — and meets the two upgrades that finally can: tools and memory. This is where Nova stops being a clever talker and starts becoming an agent.