What Is Prompt Engineering and How Do You Write Better Prompts?
Updated
Prompt engineering is the practice of designing and refining the text you send to a large language model (LLM) so that its output is accurate, relevant, and usable. You write better prompts by being explicit about the role, task, context, output format, and constraints, then testing and revising based on the results. This guide covers the core concept, the main techniques and when to use them, a reusable prompt structure, common failure modes, and how to evaluate your prompts. It is for anyone who wants more reliable AI output, whether you are new to prompting or already using LLMs regularly.
What prompt engineering actually is
An LLM does not read your mind. It predicts a continuation based on the text you give it. Prompt engineering works because the input shapes that prediction: the same model can produce a vague answer or a precise one depending on how the request is framed.
This is why two prompts asking for the "same thing" can produce very different results. "Summarize this" leaves the length, audience, and focus open. "Summarize this customer feedback in three bullet points for a product manager, focusing on recurring complaints" narrows the space of acceptable outputs.
Prompt engineering is not a single trick. It is a set of techniques you choose from depending on the task, plus a habit of iterating.
Common prompting techniques and when to use them
| Technique | What it looks like | Best for |
|---|---|---|
| Zero-shot | Just the instruction, no examples | Simple, well-defined tasks the model likely has seen many times |
| Few-shot | Instruction plus 2–5 examples of input and desired output | Tasks with a specific format, tone, or pattern the model should imitate |
| Chain-of-thought | Ask the model to reason step by step before answering | Multi-step reasoning, math, logic, or decisions with several factors |
| Role or persona | "You are a senior editor reviewing…" | Setting tone, expertise level, and evaluation criteria |
| Output formatting | Specify JSON, a table, a numbered list, or a fixed schema | When the output feeds into another tool or must be consistent |
A few practical notes:
- Zero-shot first. Try the simplest version before adding complexity. Many tasks do not need examples.
- Few-shot when format matters. If you need a particular structure, showing two or three examples is usually more effective than describing the structure in words.
- Chain-of-thought when the answer requires reasoning. Forcing an answer without intermediate steps tends to produce confident but wrong results on multi-step problems. Asking for the reasoning first, then the conclusion, improves reliability.
- Combine techniques. A role plus a format plus one example is often stronger than any single technique alone.
A reusable prompt structure
You can build most prompts from five components. Not every prompt needs all five, but when output is disappointing, checking which component is missing usually reveals the fix.
- Role — Who should the model act as? "You are a technical writer explaining this to a non-technical audience."
- Task — What exactly should it do? Use a specific verb: summarize, classify, rewrite, compare, extract.
- Context — What background does it need? Paste the source text, describe the audience, or state the goal.
- Output format — What should the result look like? Specify length, structure, and format (bullets, table, JSON).
- Constraints — What should it avoid or respect? Word limits, tone, things to exclude, assumptions not to make.
A filled-in example:
You are a customer support lead. (role)
Rewrite the following refund policy so a first-time buyer can understand it. (task)
The audience is non-native English speakers shopping on mobile. (context)
Return it as a short intro paragraph plus five bullet points, each under 20 words. (format)
Do not use legal jargon or promise anything the original policy does not state. (constraints)
If you only remember one thing: state the task and the output format explicitly. Most weak prompts fail on one of those two.
Common failure modes and how to fix them
Vague instructions. "Make this better" gives the model no target. Fix: name the dimension — clearer, shorter, more formal, more persuasive.
Missing examples. The model guesses at your format and guesses wrong. Fix: add two or three input–output examples.
Context overload. Pasting ten pages when only one paragraph matters dilutes the signal and can push the model to miss the relevant part. Fix: include only the context the task requires, and point to it directly ("Using only the section titled Billing…").
Conflicting constraints. "Be concise but cover every detail" forces the model to choose. Fix: prioritize — "Cover the three most important points in under 100 words."
Assuming shared knowledge. The model does not know your internal project names, acronyms, or history. Fix: define terms or provide the background inline.
No format specification. You get a wall of text when you needed a list. Fix: state the structure you want.
How to test and improve a prompt
Treat prompting as a loop, not a one-shot attempt:
- Write a first version using the five-component structure.
- Run it on more than one input if the task is repeatable. A prompt that works once may fail on a different case.
- Compare outputs against a clear criterion. Decide in advance what "good" means — correct facts, right format, appropriate tone.
- Change one thing at a time. If you rewrite everything at once, you will not know what helped.
- Keep the version that performs best across your test cases, not just the one that produced a good answer once.
For tasks you will repeat, save your working prompt as a template with placeholders for the parts that change. This turns a one-off success into a reusable tool.
Where to learn more
Learn Prompting describes itself as a large and comprehensive prompt engineering course, with over 60 content modules translated into 9 languages and a community of more than 3 million learners. Its materials cover prompting fundamentals as well as adjacent areas such as AI red-teaming and LLM security, including a free 7-day "Learn Prompt Hacking" course and an AI/ML Red-Teaming & AI Security Masterclass. The site lists a pricing page, so check there for current access and cost details rather than assuming all content is free.
If you are starting out, the practical path is: learn the five-component structure, practice zero-shot and few-shot prompting on real tasks, add chain-of-thought when reasoning is involved, and build the habit of testing prompts against more than one input before relying on them.