Give Context Before You Give the Task
The AI cannot see your project the way you can. It does not know your version, your file structure, or the conventions you have already established. When you skip this, it guesses — and guesses badly. Worse, it guesses confidently, so the output looks plausible until it collides with your actual codebase.
Compare these two prompts for the same request.
Add a function to validate emails.
This is a TypeScript backend using Express and Zod for validation.
We already validate inputs with Zod schemas in src/schemas/.
Add an email validation schema in that style. Emails must be
lowercase, max 254 chars, and reject disposable domains from
the existing BLOCKED_DOMAINS list in src/config.ts.
The first produces generic code that may use a regex you do not want, in a style that does not match your codebase. The second produces code you can paste in. The rule: state the stack, the conventions, and the existing pieces the AI should reuse.
A good prompt stacks these pieces in order, from the ground up — context at the base, the actual request near the top:
┌──────────────────────────────┐
│ EXAMPLES │ one input → output
├──────────────────────────────┤
│ CONSTRAINTS │ what NOT to do
├──────────────────────────────┤
│ EDGE CASES │ empty, invalid, errors
├──────────────────────────────┤
│ INPUTS / OUTPUTS │ types and shapes
├──────────────────────────────┤
│ GOAL │ one clear task
├──────────────────────────────┤
│ CONTEXT │ stack, files, patterns
└──────────────────────────────┘
foundation first ▲
A useful mental checklist before you hit enter: language and framework (with version if it matters), the relevant files or modules, the patterns already in the project, and any libraries the AI should prefer or avoid. You do not need all four every time — but if the answer would change depending on one of them, name it. When in doubt, paste the actual signature, type, or config the new code has to fit against. A few lines of existing code teach the AI more about your conventions than a paragraph of description ever will.