AI Literacy for Developers·A reliable AI workflow

Writing better prompts

A good prompt names the role, gives context and constraints, shows examples, and asks for a plan before code.

Beginner 12 min read Lesson 2 of 300 Challenge included
What you will be able to do
  • State a role, a goal and concrete constraints.
  • Provide the smallest context that contains the answer.
  • Give an example of the exact output you want.
  • Ask for a plan and assumptions before large changes.

In plain English

Writing a better prompt means telling the model who it should act as, what you want, what limits it must follow and what shape the answer should take. Context is the specific information you give it, and providing the smallest relevant context keeps the answer focused and inside the context limit. Examples are one of the strongest signals you can send, because they show the exact pattern you want instead of describing it in words. For any task larger than a small edit, ask the model to write a plan first so you can correct its understanding before it writes code. If your request is ambiguous, ask it to list the assumptions it made so you can catch wrong guesses early.

Step by step

  1. 1Rewrite a vague request as a role plus a goal.
  2. 2Cut the context down to only what the answer depends on.
  3. 3Add one example showing the output format you expect.
  4. 4For a multi-step task, ask for a plan before any code.
  5. 5Ask the model to list assumptions when the requirement is unclear.
structured-prompt.txtText
Role: a careful TypeScript reviewer
Goal: find bugs in the function below
Context: runs in Node 22, no framework
Constraints:
- no style suggestions yet
- at most 5 findings
- do not invent APIs
Output: JSON array of {line, issue, severity}
If anything is ambiguous, list your assumptions first.

Common mistakes

  • Leaving the role and constraints out invites a generic answer that ignores your real situation.
  • Pasting a huge codebase without focus wastes the context limit and buries the relevant part.
  • Asking for the best solution without examples gives you a vague answer you cannot judge.
  • Skipping the plan step on a big task lets the model guess your intent and run far in the wrong direction.
Your turn

Upgrade a vague prompt

Easy

Take the starter prompt and add a role, one constraint, and an output format. Keep it under five lines.

TEXT · starter
Help me with my React app.
Check your understanding before moving on.
Knowledge checkQuestion 1

Which part of a prompt most reliably steers the output format?

Select an answer to continue
Study tools

Make it yours.

Keep a private note for this lesson, then turn the key ideas into flashcards you can revisit.

Sign in to save notes and flashcards.Both are private to your account and stay with your progress.
Sign in
Finished reading?

Lock in what you just learned.

Mark this lesson complete to save your place and move one step closer to the certificate.

Next: Evaluating answers
Lesson 2 of 300 · 0% of course