Generative AI Fundamentals · 7 min read

Prompt Patterns for Coding with AI

Learn prompt structures that get more accurate, reviewable code out of an AI coding assistant instead of confident-looking guesses.

By aijobsok Editorial TeamPublished 2026-07-19Updated 2026-07-28

Why vague coding prompts fail

Asking an assistant to "add rate limiting" or "fix this bug" without further detail forces it to guess at your stack, existing patterns, and constraints, and it will guess plausibly rather than admit uncertainty. The single highest-leverage fix is stating the language, framework, existing dependencies, and the exact file or function in scope before asking for a change.

State constraints before asking for code

Tell the assistant what it must not do just as clearly as what it should do: do not add new dependencies, do not change the public function signature, do not touch unrelated files. Without explicit constraints, an assistant will often "improve" surrounding code you did not ask it to touch, which turns a small change into a large, harder-to-review diff.

A structured coding prompttext
Language/stack: TypeScript, Node 22, Express
Task: Add a rate limiter middleware for the /login route.
Constraints: use only existing deps in package.json; no new packages.
Must include: unit tests for the 429 response and a config comment
explaining the window and limit values.
Return: a unified diff, not a full-file rewrite.

Ask for a diff, not a rewrite

For an existing codebase, requesting a unified diff or a clearly marked patch rather than a full-file rewrite makes the change far easier to review and reduces the chance that unrelated code gets silently altered or reformatted. Full-file rewrites are appropriate mainly for new, small files where there is nothing yet to preserve.

Request tests alongside the change

Explicitly asking for a test that exercises the new behavior — including the failure case, like a 429 response for a rate limiter — surfaces problems in the suggested code before it reaches review. An assistant asked only for the feature code will frequently skip edge cases that a test forces it to consider.

Verify, do not trust

Generated code can reference a function, parameter, or library behavior that does not exist, especially for less common APIs or recent version changes. Always run the code, run the type checker, and run the test suite rather than accepting a plausible-looking diff on sight — this is not optional even when the assistant sounds confident.

Practical exercise

Take a real, small task from your current backlog. Write two versions of the prompt: one vague (a single sentence) and one structured with stack, constraints, and a request for tests, using the pattern above. Run both through an assistant and compare how much manual correction each result needed before it would pass review.

By aijobsok Editorial TeamPublished 2026-07-19Updated 2026-07-28

Sources and further reading

These primary or specialist references informed the concepts in this guide. Product details can change, so verify current documentation before implementation.