AI Prompt Engineering Guide
Good prompting is a learnable, practical skill -- here's what actually improves output quality, with real examples.
Example: A Vague Prompt vs. a Specific One
Vague: "Write a function to validate an email." Specific: "Write a Java method that validates an email address using a standard regex pattern, returns a boolean, handles null input by returning false rather than throwing, and includes a short comment explaining the regex." The specific version removes ambiguity about language, edge case handling, and expected behavior -- all things the vague version leaves the model to guess about, often incorrectly.
Core Techniques
- Be specific about format, constraints, and edge cases -- don't leave the model to guess
- Give an example of the desired output style when the format matters ("few-shot" prompting)
- Break a complex task into explicit steps rather than one giant, vague request
- State what NOT to do when a common wrong answer is likely ("don't use deprecated APIs," "don't add error handling I didn't ask for")
- Ask the model to explain its reasoning when you need to verify correctness, not just accept a final answer
Example: Breaking Down a Complex Task
Instead of: "Build me a user authentication system." Break it into explicit steps: "1) Design a User entity with email, hashed password, and role fields. 2) Write a registration endpoint that hashes the password with BCrypt before saving. 3) Write a login endpoint that verifies credentials and returns a JWT. 4) Write a filter that validates the JWT on protected routes." Each step is small enough to review and verify individually, rather than getting one large, harder-to-audit response covering everything at once.