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.

TeTeemu Puuska
7 min read
Icons (sticker, pencil, terminal) on dark background

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.):

PrincipleWhat it meansWhy it matters / tip
Be specific & clearDescribe exactly what you wantThe more detail, the less guesswork for the AI.
Include relevant contextGive background, constraints, domain knowledgeThis helps the AI “get on the same page.” From OpenAI community guidance: “Provide context matters.”
Provide examples (few-shot)Show sample outputs, input/output pairsHelps 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 subtasksInstead of one big prompt, chain or stepwise approachEasier for the AI; more reliable.
Let the model “think” / chain-of-thoughtAsk it to reason step by step before finalizingHelps with complex reasoning tasks.
Iterate & experimentTry small tweaks, compare resultsPrompt engineering is often trial and error.
Avoid ambiguity / conflicting instructionsDon’t tell it “do X and not Y” in a confusing wayThe AI might pick the wrong constraint to obey.
Constrain structure / format if neededDemand “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:

PitfallWhat goes wronghow to avoid
Overly long, bloated promptThe model gets confused, contradicts itselfOnly include relevant detail; break into parts
Ambiguous / vague wordingThe AI makes unintended assumptionsUse precise language; provide examples
Contradictory instructionsAI picks one and ignores othersMake instructions consistent
Too much “don’t do this” languageNegative constraints are harder to enforcePrefer positive instructions (tell what to do)
Forgetting format / output structureYou get prose when you wanted bulletsClearly specify “Output as bullets / JSON / table”
Assuming the AI “knows what I meant”It will often misinterpret implicit intentSpell out your goals, context, etc.
Not iterating or testing variantsYou might miss a better prompt versionAlways test tweaks, compare outputs

Prompt writing workflow (step-by-Step)

Here’s a repeatable method you can follow:

  1. Define goal / output Be very clear what you want (summary, code, article, list, etc.).
  2. Decide format / constraints E.g. bullet list, JSON, “5 points,” tone = casual, academic etc.
  3. Draft a first prompt Combine your goal, context, persona, example outline.
  4. Run & inspect results See where the AI misinterprets, fails, or goes off track.
  5. Refine: add clarity, examples, constraints Fix ambiguous parts, include sample output, reorganize.
  6. Test variants (A/B), compare Slight changes can yield big improvements.
  7. (Optional) Use chaining / meta-prompts For complex tasks, break into subprompts or ask the model to self-check.
Visualization image of prompt writing workflow
Visualization image of prompt writing workflow

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

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.

SCORE: 00000LVL: 1
Full heartFull heartFull heart
Geosaur

GEOSAUR SURVIVAL

Don't let your brand go extinct in the new era of search. Collect credits with Geosaur and avoid meteors.

Left arrowRight arroworA keyD keyto move