Language models write code well when they know what you're building and how your codebase works.
Provide Context
- Language, framework and versions.
- Relevant existing code: related functions, data models, conventions.
- Where the code will run and constraints (performance, dependencies allowed).
Specify Behaviour
Describe inputs, outputs, edge cases and error handling. Examples of expected input and output are especially effective.
Ask for Tests
Request unit tests covering normal and edge cases. Run them. Tests catch misunderstandings early.
Small Steps
Ask for one function or change at a time. Large generated changes are hard to review and debug.
Review Like a Colleague's Code
- Does it actually solve the problem?
- Do the libraries and functions exist, and are they current?
- Security: input validation, injection, secrets, unsafe deserialisation.
- Readability and consistency with the codebase.
Debugging Prompts
Include the exact error message, stack trace, the code involved, what you expected and what you've tried.
Explanations
Ask the model to explain unfamiliar code or its own changes — useful for learning and for checking its reasoning.
Stay Accountable
You own the code you commit. Understand it well enough to maintain it.