This content originally appeared on DEV Community and was authored by Mario Herreros
GenAI is transforming the way developers write and refine code. From generating boilerplate to debugging complex issues, AI can save hours of work—but only if you ask it the right way. The secret? Crafting clear, detailed prompts.
Think of your prompt as the specification document for the AI. If it’s vague, you’ll get something generic. If it’s precise, you’ll get code that fits your needs.
To make this easy, use PARTS:
P – Persona: Identify Your Role
Start by telling the AI who you are and your context. This shapes the complexity, depth, and tone of the response.
Examples:
- I am a backend engineer working on a microservices architecture using Node.js.
- I am a DevOps specialist automating CI/CD pipelines for a Kubernetes environment.
- I am a full-stack developer integrating Stripe payments into a React app.
Why it matters: A DevOps engineer might expect infrastructure-as-code templates, while a backend engineer wants clean, modular functions.
A – Aim: State Your Objective
Clearly state what you want the AI to do. Start with a strong verb: write, debug, optimize, explain, convert, etc.
Examples:
- Write a Python script to upload large files to AWS S3 using multipart upload.
- Debug the following Dockerfile for a Node.js app that crashes on startup.
- Optimize this SQL query for faster performance on a 10M-row PostgreSQL table.
- Convert this Express.js middleware to TypeScript with proper types.
Pro tip: Always specify the language, framework, and purpose. “Write a login feature” is vague. “Write a Next.js API route for user authentication using JWT” is clear.
R – Recipients: Specify the Audience
Who will use this code? Your audience determines complexity and style. Is it for:
- Your dev team (production-ready, optimized, minimal comments)
- Open-source contributors (clean, documented, maintainable)
- Junior developers (extra comments, educational tone)
Examples:
- The code should be production-ready for a fintech app with strict security requirements.
- Output should include comments for maintainability because multiple teams will contribute.
- Provide a lightweight solution that avoids external dependencies for a performance-critical system.
T – Theme: Define Style and Constraints
This is where you set coding conventions, tone, and any restrictions.
Examples:
- Follow PEP 8 guidelines and include type hints.
- Use functional programming principles; no OOP classes.
- Avoid any third-party libraries; stick to Node.js core modules.
- Add inline comments explaining performance trade-offs.
S – Structure: Specify the Format
Decide how you want the answer delivered. Just code? Code + explanation? Step-by-step?
Examples:
- Provide the final code only—no explanation.
- Show the code, then explain the solution in bullet points.
- Include unit tests using Jest for the provided function.
- Give two versions: a basic solution and an optimized one.
Example of a Full Prompt Using PARTS
Here’s how you can combine everything into a real-world scenario:
I am a backend engineer building a payment service (Persona). Write a Node.js function to generate Stripe payment intents with error handling (Aim). The code will be reviewed by senior developers and deployed to production (Recipients). Use modern JavaScript (ES2022) and include JSDoc comments for maintainability (Theme). Provide the function and an example usage snippet (Structure).
Why PARTS Makes Your Prompts Better
By applying PARTS, you turn vague instructions like:
“Write code to handle payments.”
Into:
“I am a backend engineer building a payment service. Write a Node.js function to generate Stripe payment intents with error handling. The code will be reviewed by senior developers and deployed to production. Use modern JavaScript (ES2022) and include JSDoc comments for maintainability. Provide the function and an example usage snippet.”
The second prompt gives the AI context, goals, and constraints, resulting in code that’s closer to what you actually need—saving you time and reducing rewrites.
✅ Pro-Tip: Test and Iterate
Prompt engineering is like debugging: the first try may not be perfect. Iterate, refine, and add details until the output meets your expectations.
Not Just for Coding
Although this article focuses on coding, the PARTS works for many other domains:
- Design: I am a UX designer creating wireframes (Persona). Suggest 5 user flow improvements for a food delivery app (Aim)...
- Content Writing: I am a tech blogger writing an article on AI ethics (Persona). Generate 10 catchy titles (Aim)...
- Project Management: I am a product manager preparing a sprint plan (Persona). Create a roadmap for a SaaS product launch (Aim)...
Any time you need AI to generate content, brainstorm ideas, analyze data, or create structured output, PARTS gives you a blueprint for clarity and precision.
This content originally appeared on DEV Community and was authored by Mario Herreros

Mario Herreros | Sciencx (2025-08-19T14:42:00+00:00) How to Craft Effective Prompts Using PARTS. Retrieved from https://www.scien.cx/2025/08/19/how-to-craft-effective-prompts-using-parts/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.