Garbage In, Garbage Out
If you tell an AI "Write a login function," you will get generic, possibly insecure code that doesn't match your stack, your conventions, or your requirements. The AI is not being lazy — it simply has no information to do better. It will make assumptions, and those assumptions will be wrong.
To get production-quality output, you must treat the prompt like a technical specification. The more context you provide, the less the AI has to guess.
The 4 Pillars of a Good Code Prompt:
- Role/Context: Establish the environment. "You are a Senior Python Engineer working on a FastAPI backend. The project uses
pydanticv2 for data validation." - Constraint: State what tools, patterns, or styles to use or avoid. "Use pure functions, not classes. Do not use
try/exceptfor control flow." - Input/Output contract: Define the function signature precisely. "Take a raw JSON string as input. Return a validated
Userpydantic model, or raiseValidationErrorif the data is invalid." - Edge cases: Explicitly name the failure modes you care about. "Handle the case where the
emailfield is missing or malformed. Handle the case where the JSON string itself is not valid JSON."
Prompt quality comparison:
| Quality | Prompt |
|---|---|
| Bad | "Fix this code." |
| Mediocre | "This function crashes sometimes, fix it." |
| Good | "This function raises KeyError when the 'id' field is missing from the input dict. Rewrite it to use .get() with a default of None, and add a docstring explaining the expected input shape." |
Iterative prompting is also a skill. You rarely get perfect output on the first try. A productive loop looks like:
- Send a prompt → get output.
- Identify what's wrong or missing.
- Send a follow-up: "Good, but now add error handling for the case where
user_idis not a valid UUID." - Repeat until the code meets your standard.
Think of it like pair programming with a very fast junior developer who needs clear direction but can execute quickly once they understand the task.
Interviewers at senior levels increasingly ask: "How do you use AI tools in your workflow?" The wrong answer is "I don't" (signals resistance to productivity tools) or "I just use whatever it gives me" (signals lack of critical judgment). The strong answer is: "I use AI for scaffolding and boilerplate, I write detailed prompts that include constraints and edge cases, and I always review the output for correctness, security implications, and consistency with our codebase conventions before committing."
Key Point: Specificity in prompts directly correlates with code quality. The skill of writing a good prompt is structurally identical to the skill of writing a good ticket or technical spec — it requires you to have already thought through the problem clearly.