Effective Prompting for Code
Getting good code out of an agent is not about magic words. It is about being specific about the goal and the constraints — saying clearly what you want and what the agent must not do.
What a Good Request Says
A strong prompt for code carries four things. Miss one and the agent fills the gap with a guess.
- The goal — what the code should do, in plain terms.
- The scope — which files to touch, and what to leave alone.
- The constraints — style, libraries, patterns to follow or avoid.
- How you’ll check it — the acceptance criteria that make “done” concrete.
Scope It Tightly
One clear task beats a vague mega-request. A small scope is easier for the agent to get right — and easier for you to verify and to undo when it goes wrong.
Say When It’s Done
Give the acceptance criteria up front. Stating “done when the tests pass” or “done when it does X” turns a fuzzy ask into something you can actually check.
- A checkable target lets the agent tell for itself whether it succeeded.
- It anchors your review — you know what to look for.
- Module 4 takes this further: write the test first, then ask for the code.
Expect to Iterate
The first output is a draft you steer, not a final answer. Read it, point at what is off, and refine. Prompting well is a conversation — not one perfect sentence you have to get right on the first try.
Build It
How to implement: take a vague request like “make it better” and rewrite it into goal + scope + constraints + acceptance criteria — then use that version to prompt your agent.
- Weekly AI Tasks tracker — “add an endpoint that returns this week’s tasks as JSON, don’t touch the auth code, done when this test passes” is a model prompt.
- Personal brand site — “write the projects section from these repos, 3 bullets each, no claims not in the source” keeps it honest and scoped.
What you learned
A good code prompt states the goal, the scope, the constraints, and how you’ll check it. Scope tight, define done up front, and expect to steer the draft.