Skip to content

Effective Prompting Techniques

Communicating effectively with an AI coding assistant is a skill. While you can get useful results with simple questions, mastering the art of prompting allows you to guide the AI’s reasoning process, leading to more accurate, well-architected, and reliable code.

This guide covers several powerful techniques that will transform your conversations with your AI partner.

The more information and constraints you provide, the better the AI can tailor its response to your exact needs. Don’t be vague.

  • Don’t say: “Add a database connection.”
  • Do say: “Add a connection to our PostgreSQL database using the pg library. The connection string should be loaded from the DATABASE_URL environment variable. Ensure the connection includes retry logic with exponential backoff.”

By providing these details upfront, you guide the AI towards the correct implementation and prevent it from making incorrect assumptions.


For any task more complex than a one-line change, force the AI to think before it codes.

  1. Ask for a Plan First. Start with a prompt that explicitly asks for a plan and forbids writing code.

    I need to add a feature that allows users to upload a profile picture. First, create a detailed, step-by-step plan for how you will implement this. List the files you will need to create or modify. **Do not write any code yet.**
  2. Review and Refine the Plan. The AI will produce an outline (e.g., “1. Create a new API endpoint /api/upload-avatar. 2. Add a file input to the ProfilePage component…”). Review this plan. If it looks good, you can proceed. If not, you can provide corrections (“Actually, let’s use a separate AvatarUpload component.”) before any code is written.

  3. Execute the Plan. Once you’re happy with the plan, give the green light.

    The plan looks good. Please proceed with the implementation.

This two-step process prevents the AI from rushing into a flawed implementation and ensures the solution is well-thought-out.


If you want the AI to follow a specific coding style, pattern, or structure, the best way to communicate that is by showing it an example.

  • Don’t say: “Create a new service class. It should have a constructor, a private logger instance, and public methods that are documented with JSDoc.”
  • Do say: “Create a new PaymentService class that follows the exact same pattern and structure as the @/services/AuthService.ts file.”

The AI is excellent at pattern recognition. By providing a concrete example, you give it a perfect template to follow.


You can prime the model to adopt a specific mindset or access a particular domain of knowledge by assigning it a role at the beginning of your prompt.

Security Expert

“You are an expert security engineer. Review this code for potential vulnerabilities like XSS, CSRF, and SQL injection. Provide a list of any issues you find and suggest fixes.”

Performance Guru

“You are a senior performance engineer. Analyze this function and identify any performance bottlenecks. Suggest optimizations to make it faster and more memory-efficient.”


Don’t treat the conversation as a single-shot question and answer. It’s a dialogue. If the AI’s first attempt isn’t perfect, guide it with follow-up instructions.

  • “That’s a good start, but you forgot to handle the case where the user is not logged in. Please add a check for that.”
  • “This implementation works, but it’s a bit hard to read. Can you refactor it to use a switch statement instead of nested ifs?”
  • “Please add a comprehensive suite of unit tests for the function you just wrote.”

By iterating and providing feedback, you can collaboratively shape the AI’s output until it meets your exact specifications.