The difference between a great answer from an AI and a useless one is usually not the model — it’s the prompt. Same model, same question, wildly different results, all depending on how you ask. Prompt engineering is the skill of asking well.
This guide gives you practical, copy-paste techniques that work across every model, from ChatGPT to a local model running on Ollama. No theory — just what actually moves the needle.
What is prompt engineering?
Prompt engineering is the practice of writing inputs that steer a language model toward the output you actually want. It’s not a magic incantation; it’s mostly about clarity, structure, and giving the model enough context to work with.
The good news: a handful of techniques cover most of the value, and they’re all easy to learn.
Why prompts matter
A vague prompt gets a vague answer. “Write me a function” produces something generic. “Write a Python function that reads a CSV file, filters rows where the ‘status’ column is ‘active’, and returns the count — with type hints and error handling” produces something you can almost ship.
Same model. Better prompt. Better result.
Be specific and give context
The single highest-leverage habit. Instead of “fix this bug,” write:
Here's the error, the relevant code, and what I've already tried.
What's the most likely cause, and what's the safest fix?
[error message]
[code]
[what you tried]
Context is everything. The model can’t read your mind or your codebase.
Give the model a role
Telling the model who to act as steers its tone and depth:
You are a senior backend developer reviewing code for a production system.
Point out bugs, security issues, and edge cases.
Roles work because they prime the model toward a particular style and level of rigor.
Provide examples (few-shot prompting)
If you want output in a specific format, show one or two examples:
Turn each feature into a test case.
Example:
Feature: "users can reset their password"
Test: "calling reset_password() with a valid token returns 200"
Now do the same for:
1. users can delete their account
2. users can export their data
One good example beats a paragraph of instructions.
Ask for step-by-step reasoning
For reasoning tasks, asking the model to think step by step dramatically improves accuracy — especially on math, logic, and debugging:
Solve this problem step by step, explaining your reasoning at each step.
This is the single most reliable quality boost for hard questions.
Specify the output format
Tell the model exactly how you want the answer structured:
Return your answer as JSON with the fields "summary", "risks", and "next_steps".
This makes the output directly usable in code and removes the “the answer is right but I have to reformat it” problem.
Iterate
Prompting is a conversation, not a one-shot. If the first answer is close but not right, don’t start over — tell the model what to change:
Good, but make it more concise, and use async/await instead of callbacks.
Iteration is where the real work happens, and it’s why chat interfaces are so effective.
Chain-of-thought vs few-shot: when to use which
Two techniques often get conflated. Here’s the distinction:
- Chain-of-thought (“think step by step”) is for reasoning — math, logic, debugging, anything with multiple steps.
- Few-shot (show examples) is for format and style — getting the model to match a structure or tone.
Use chain-of-thought when the answer is hard to get right, and few-shot when the answer needs to look a certain way. For complex tasks, combine both: give an example, then ask it to reason step by step.
Temperature and model settings
Most APIs expose a temperature setting that controls randomness. Lower it for factual, deterministic output (code, data extraction); raise it for creative work (brainstorming, headlines).
The lesson: tune the setting to the task. A high temperature on a code-generation prompt produces plausible-looking but subtly wrong code; a low temperature on a brainstorming prompt produces boring ideas.
Use system prompts for standing instructions
If you find yourself repeating the same instructions in every message — “be concise,” “prefer TypeScript,” “never invent functions that don’t exist” — move them into the system prompt instead.
The system prompt is the model’s standing instructions, and it applies to the whole conversation. Set it once and every message inherits it. For coding specifically, the habit of stating your preferences up front is half the battle — see our AI coding guide for more.
Common mistakes to avoid
- Vague prompts — “make it better” tells the model nothing.
- Asking too much at once — one clear task per prompt beats five.
- Expecting perfection on the first try — budget a couple of iterations.
FAQ
Is prompt engineering a real skill or just hype?
It’s real, but it’s mostly clear communication — specific, structured, with examples. The “engineering” part is just applying those habits consistently.
Do these techniques work on smaller local models?
Yes, though smaller models benefit even more from examples and explicit formatting, since they have less implicit knowledge than frontier models.
Does prompt engineering matter for code?
Absolutely — see our guide to using AI for coding the right way for the coding-specific version of these ideas.
A quick-reference cheat sheet
Bookmark this. The five habits that cover most situations:
- Be specific — say exactly what you want.
- Give context — code, errors, and what you’ve tried.
- Show an example — one sample beats a paragraph of instructions.
- Ask for step-by-step — for reasoning and debugging.
- Iterate — refine the output instead of starting over.
Master these five and you’ll get better results from every model you touch, from a frontier chatbot to a tiny model running on your own hardware.
The bottom line
Prompt engineering isn’t complicated: be specific, give context, show examples, and iterate. Master those four habits and you’ll get dramatically better results from every AI you use — from the frontier models to a local model running on your homelab.