How to write a prompt: a complete guide
If you’ve ever used ChatGPT, Gemini, or another AI tool, you probably got results that were… okay, but not quite what you hoped.

Introduction
If you’ve ever used ChatGPT, Gemini, or another AI tool, you probably got results that were… okay, but not quite what you hoped. The difference often comes down to the prompt you gave. A prompt is your instruction to the AI: the clearer, smarter, and more thoughtful it is, the better the output you’ll get.
In this article, you’ll learn:
- How to write prompt
- Why prompt quality matters
- Core principles and best practices
- Advanced techniques you can try
- Common mistakes to avoid
- A hands-on workflow you can follow
- Real examples to illustrate what “good vs not good” prompts look like
Let’s dive in.
Why good prompts make a big difference
Think of prompt writing like giving instructions to someone to build a piece of furniture. If you just say, “build me a shelf,” they might do something very generic, or miss parts of what you wanted. But if you say, “build a wall shelf that’s 80 cm wide, 20 cm deep, made of birch, with three compartments and mounting hardware included,” the odds of getting what you envisioned go way up.
With AI, weak prompts often lead to:
- Vague or generic answers
- Misinterpretations or hallucinations
- Outputs that miss your style, format, or detail requirements
Meanwhile, good prompts let you:
- Steer tone, style, structure
- Control length, format, and content
- Get more accurate, relevant, and useful results
Harvard’s AI prompts guide cautions that AI content may be inaccurate or misleading, so prompts should anticipate and mitigate errors.
Best practices for prompt writing
Here are foundational rules drawn from industry guides (PromptingGuide, OpenAI, etc.):
| Principle | What it means | Why it matters / tip |
|---|---|---|
| Be specific & clear | Describe exactly what you want | The more detail, the less guesswork for the AI. |
| Include relevant context | Give background, constraints, domain knowledge | This helps the AI “get on the same page.” From OpenAI community guidance: “Provide context matters.” |
| Provide examples (few-shot) | Show sample outputs, input/output pairs | Helps the model conform to your style or desired format. |
| Use roles / personas | “You are an expert historian” etc. | This frames perspective and style. |
| Break tasks into subtasks | Instead of one big prompt, chain or stepwise approach | Easier for the AI; more reliable. |
| Let the model “think” / chain-of-thought | Ask it to reason step by step before finalizing | Helps with complex reasoning tasks. |
| Iterate & experiment | Try small tweaks, compare results | Prompt engineering is often trial and error. |
| Avoid ambiguity / conflicting instructions | Don’t tell it “do X and not Y” in a confusing way | The AI might pick the wrong constraint to obey. |
| Constrain structure / format if needed | Demand “five bullet-points,” “JSON output,” etc. | Helps ensure the output is usable. |
Advanced techniques & variations
Once you grasp the basics, try these more advanced tricks:
- Prompt chaining / multi-step prompting Use the output of one prompt as input for the next. Helps with layered tasks.
- Meta-prompts / self-reflection Ask the AI to critique its own output, improve, or check for errors.
- Self-consistency / sampling Ask the AI to produce multiple outputs and then choose or merge best parts.
- Retrieval-augmented prompting / injection of external data Feed in external text, documents, or knowledge sources and ask the AI to reference them.
- Guardrails / constraints Force the model to respond in a way (e.g. “if you don’t know, say ‘I don’t know’”).
- Prompt migration & optimization If you had a prompt for an older model (or tool), you can “migrate” it to a newer, better architecture. OpenAI Cookbook has a “prompt migration” notebook.
- Lazy prompting (advanced) Sometimes a minimal prompt works, especially when the model is strong enough to infer your intent. Andrew Ng discusses this for code debugging.
Common pitfalls & how to avoid them
Here are frequent mistakes and mitigation tips:
| Pitfall | What goes wrong | how to avoid |
|---|---|---|
| Overly long, bloated prompt | The model gets confused, contradicts itself | Only include relevant detail; break into parts |
| Ambiguous / vague wording | The AI makes unintended assumptions | Use precise language; provide examples |
| Contradictory instructions | AI picks one and ignores others | Make instructions consistent |
| Too much “don’t do this” language | Negative constraints are harder to enforce | Prefer positive instructions (tell what to do) |
| Forgetting format / output structure | You get prose when you wanted bullets | Clearly specify “Output as bullets / JSON / table” |
| Assuming the AI “knows what I meant” | It will often misinterpret implicit intent | Spell out your goals, context, etc. |
| Not iterating or testing variants | You might miss a better prompt version | Always test tweaks, compare outputs |
Prompt writing workflow (step-by-Step)
Here’s a repeatable method you can follow:
- Define goal / output Be very clear what you want (summary, code, article, list, etc.).
- Decide format / constraints E.g. bullet list, JSON, “5 points,” tone = casual, academic etc.
- Draft a first prompt Combine your goal, context, persona, example outline.
- Run & inspect results See where the AI misinterprets, fails, or goes off track.
- Refine: add clarity, examples, constraints Fix ambiguous parts, include sample output, reorganize.
- Test variants (A/B), compare Slight changes can yield big improvements.
- (Optional) Use chaining / meta-prompts For complex tasks, break into subprompts or ask the model to self-check.

Examples of how to write prompt
Here are some before / after style examples:
Example 1: Article summary
- Weak prompt: “Summarize this article.”
- Improved:
“You are a professional editor. Summarize the following 1,200-word article into five bullet points, each 15–20 words max. Then provide a compact 30-word overall summary.”
Example 2: Code generation
- Weak: “Write Python script to sort list.”
- Better:
“You are an experienced Python developer. Write a Python function sort_numbers(nums: List[int]) -> List[int] that sorts the list ascending using quicksort and includes docstring, example usage, and error handling.”
You can show how small tweaks (role, constraints, examples) dramatically change output.
Additional resources for prompt writing
- OpenAI Cookbook — a collection of prompt patterns, techniques, migrations.
- PromptingGuide.ai – interactive and up-to-date prompt tips.
- OpenAI official prompt engineering guide (Platform docs)
- Technical blogs by DigitalOcean with prompt best practices
- Community forums / Reddit threads — real examples, pitfalls, user tricks
You might also share or link to your own favorite prompt templates, cheat sheets, or GitHub repos.
Key takeaways
Good prompts are not magic, but they are powerful. Some final reminders:
- Be explicit, clear, and directive
- Provide enough context and examples
- Use constraints, structure, and personas
- Break hard tasks into smaller ones
- Iterate, test, and refine
Your prompt becomes your “conversation partner’s instructions” — treat it carefully. The better you frame it, the more useful the AI’s output will be.
