The truth is that when you use AI, you most likely throw out an instant query and hope for the best. It sometimes works, but many times it does not give you what you wanted from it. This is because the AI itself is not the problem, but the prompt is.
Imagine yourself getting a new teammate who asks for detailed information if all you asked for was fixing a bug. This is the same in AI. Prompt engineering is simply providing adequate instructions and context for AI to generate a proper response.
Table of Contents
The Different Types of Prompts You'll Actually Use
- Instruction prompts: You're just telling it to do a task, straight up. "Write a function that reverses a linked list." No examples, no back and forth, just a clear ask.
- Few-shot prompts: You show it one or two examples of the kind of output you want, then ask for more. This works really well when the format matters, like a specific commit message style or a particular way of writing test cases.
- Role-based prompts: You tell it to act as a specific kind of expert, like a security engineer or a code reviewer. Covered this one above, but it's worth knowing it as its own category.
- Chain-of-thought prompts: You ask it to reason step by step before landing on an answer. Great for debugging or algorithm problems where the "why" matters as much as the "what."
- Iterative prompts: You're not aiming for one perfect message. You start broad, then narrow it down based on what comes back, going back and forth a few times.
| Type | Bad Prompt | Good Prompt |
| Instruction | "Write a login function" | "Write a login function in Node.js using Express that checks a hashed password against a MongoDB record and returns a JWT on success" |
| Few-shot | "Write test cases for this function" | "Here are two examples of how we write test cases on this team: [example 1], [example 2]. Now write test cases for this function in the same style." |
| Role-based | "Is this code okay?" | "Act as a senior engineer doing a PR review. Point out anything you'd flag, including naming, readability, and edge cases." |
| Chain-of-thought | "Why is this loop slow?" | "Walk through this loop step by step and explain where the time is actually being spent before telling me how to fix it." |
| Iterative | "Explain caching" | "Explain caching strategies," then following up with "now narrow that down to a read-heavy API with occasional writes" |
Notice the pattern across all of them. The bad version is short and vague, and the good version gives the model something concrete to react to, whether that's an example, a role, a format, or a specific scenario. Once you can spot which type of prompt a situation actually calls for, picking the right one becomes second nature.
What language you're using: "Optimize this" means something totally different in Python versus Rust. Say which one.
What the code is meant to do: Even one line like "this removes duplicates but keeps the order" helps a ton.
Anything you can't change: No external libraries, tight memory limit, has to stay backward compatible, whatever it is, mention it upfront.
Look at the difference this makes:
Weak Prompt:
Better Prompt:"Fix this function"
The second one basically hands the model a real problem to solve instead of a guessing game."This Python function should remove duplicates while keeping the original order. It breaks on lists with unhashable items. Fix it without adding new libraries."
Avoid asking for the Whole Thing at Once
We've all done this. "Build me the entire feature" in one message, and then you get back a giant wall of code that's half right, and you have no idea where to even start checking it. Funny enough, we already know not to do this when we're writing code ourselves. Nobody writes a whole feature in one giant function. Prompts deserve the same treatment.
- Ask for one piece at a time: Data model first, then the logic, then the tests. Small pieces are just easier to check.
- Actually read what you get before moving on: If something's off in step one, you want to catch it there, not three prompts later when it's baked into everything.
- Build on what's already there: Reference the earlier answer instead of re-explaining your whole project every single time.
So instead of "build user login," you'd ask for the database schema, then the signup route, then the login route, then the tests. One thing at a time. Much easier to actually review.
Show It an Example Instead of Just Describing What You Want
Saying "don't write it like this" is a lot weaker than just showing what good looks like. AI is basically a pattern-matcher, so give it a pattern to match instead of a list of complaints.
- Paste a snippet: If your team has a style, drop in a small example. It'll pick up on naming and structure faster than you'd think.
- Point at existing code: "Match the style of this function" plus the actual function usually beats three paragraphs of explaining your style guide.
- Say the format you want: Table, bullet list, JSON, whatever. Just say it directly instead of hoping it guesses right.
Something like, "write a new endpoint that follows the same error handling as this one," with the old endpoint pasted in, will usually do more good than a long written description ever could.
Ask "Why" Before You Ask for Code
If AI just hands you code with zero explanation, you're stuck either trusting it blindly or spending time figuring out why it even works. Just ask for the reasoning first. It's a small ask that saves a lot of backtracking later.
- Ask how it plans to solve it before it writes anything: If the approach is wrong, you'll know before wasting time on the actual code.
- Ask what the trade-offs are: Most problems have more than one way to solve them. Knowing why it picked this one tells you if it's really the right fit for your situation.
- Ask what could go wrong: A quick heads-up on edge cases is often more useful than the code itself.
Try something like, "before writing code, explain how you'd cache this API response and mention any downsides." That one question turns a black box into something you can actually judge for yourself.
Treat It Like a Conversation, Not a One-Shot Request
The first answer you get almost never needs to be the last one. That's completely normal. Good prompting isn't about nailing the perfect message on your first try; it's more like a back-and-forth, kind of like reviewing someone's PR together.
- Call out when an answer feels generic: Instead of starting over, just say what's missing. It's faster than rewriting your whole prompt.
- Get more specific as you go: Start with "explain caching strategies," then narrow it to "for a read-heavy API with occasional writes" once you see the first response.
- Ask it to pick between its own suggestions: If it gives you three options, ask which one it'd actually go with for your case, and why.
Going back and forth like this almost always gets you somewhere better than trying to cram every possible detail into one giant opening message.
Give It a Role When It Actually Helps
Sometimes just telling the model what kind of person to "be" changes the whole answer. It's not magic; it just points the model toward the right tone and depth for what you're asking.
- Be clear about the role: "Act like a senior backend engineer reviewing this PR" gets a noticeably different response than a plain question.
- Match the role to what you're doing: For security stuff, ask it to act like a security engineer. For speed concerns, ask it to think like someone chasing low latency.
- Skip it for simple questions: If you just need a quick fact, a role usually doesn't add much. Save it for the stuff where perspective actually matters.
Try, "Act as a code reviewer who's picky about readability, review this and flag anything you'd bring up in a PR." That framing tends to get sharper, more useful feedback than just asking "is this fine?"
Actually Test Your Prompts
Here's something most people never do: they use the exact same prompt over and over and just assume it works. But a prompt that worked once might completely fall apart on a slightly different input, same as code.
- Try edge cases: If your prompt is about input validation, throw an empty string or a weird huge number at it and see if it still holds up.
- Save what works: Once you land on a prompt that reliably gives good results, keep it around as a template instead of writing it fresh every time.
- Notice repeated mistakes: If AI keeps making the same wrong assumption again and again, that's usually your prompt missing something, not the model just being off that day.
Once you start treating prompts as something worth refining and reusing, this stops feeling like trial and error and starts feeling like an actual skill you're building.
Conclusion
Frequently Asked Questions (FAQs)
1. Does prompt engineering even matter anymore with newer models?2. Should my prompts be really long and detailed?Yeah, it still does. Better models just mean a bad prompt fails less badly. A clear one still gets you a better, faster answer no matter how good the model is.
Not necessarily. Length isn't really the point, clarity is. A short prompt with the right details beats a long one full of stuff that doesn't matter.3.Isn't asking for reasoning first just slower?
4. Can I reuse the same prompt across different projects?It adds a small step, sure, but it usually saves time overall since you catch a bad approach before it's already built, not after.
5. Is giving AI a "role" a real technique or just a gimmick?Definitely, and you should. Keep a few go-to prompts for things like code review or writing tests, and just tweak the details each time.
6.What's the biggest mistake people make with prompts?It's real for stuff like security or performance reviews, where perspective actually changes the answer. For simple questions, it usually doesn't do much.
Taking the first answer as final. Most people don't push back or ask a follow-up, even when the answer is obviously too generic for what they actually needed.
0 Comments