The Code Prompts That Work
Reviewed by Human · Updated August 25, 2026
What Makes a Code Prompt Actually Work?
Here's the fastest way to get bad code out of an AI: ask it for code. The moment you type "write me a function that..." you've handed it a blank check and told it to guess at every decision you left out—language, edge cases, dependencies, what "done" even means. The model isn't short on coding ability. It's short on *your* context. The prompts that work give it the same three things you'd give a human contributor joining your repo: what you're building, the constraints it has to respect, and what a finished result looks like. Through this whole course you'll see one lesson on repeat—for code, context is everything. Pair that context with specific instructions about language, version, and constraints, and the model stops guessing. **Code prompt**: a request that gives an AI enough context about your codebase, constraints, and goal to produce code you can actually use.
✗ Wrong way
Write me a function to validate emails.
The model picks a language you didn't specify, invents a regex that rejects perfectly valid addresses, ignores your framework, and ships zero tests. Every gap got filled with an assumption—and assumptions are exactly where bugs live.
✓ Better way
In TypeScript, write an isValidEmail(input: string): boolean function. Follow RFC 5322 loosely: accept plus-addressing and subdomains, reject spaces and missing TLDs. It's called on form submit, so keep it synchronous and dependency-free. Include 6 Jest test cases covering the tricky ones.
Language, signature, rules, usage context, and a testing bar. There's nothing left for the model to invent.
The single biggest upgrade to any code prompt isn't a better description of what you want.
Bare request vs. contextual request
✗ Blank check
No language, no retry limit, no backoff strategy, no definition of what counts as a failure. You'll get someone's textbook answer, not something that survives contact with your service.
✓ Contextual request
Every decision the model would otherwise guess—language, what to retry, how many times, backoff shape, failure behavior, dependencies—is pinned down.
Your turn
Take this blank-check prompt and rewrite it so the model has nothing left to guess. Add language/version, at least two constraints, and a definition of done.
Reflect
Notice how much of "good prompting" is just refusing to leave decisions to chance.
You've finished this module.
Mark it complete to earn your XP and keep your streak alive.
Progress saved locally · Sign up to earn XP