Table of Contents
Writing the perfect AI prompt can often feel like a frustrating game of trial and error. You have a task in mind, but the initial prompt you write produces a result that’s bland, inaccurate, or cluttered with messy code you don’t need.
Today, we’re going to explore a simple yet powerful approach to drastically improve your prompts by leveraging the AI model itself.
The Iterative Prompt Improvement Cycle
The core of this technique is a simple feedback loop. Instead of just trying to guess what a better prompt would be, you provide concrete examples of what went wrong and ask the AI to fix the instructions (the prompt) that led to the mistake. We call the prompt used to improve another prompt a “meta-prompt.”
The process looks like this:
Let’s walk through two real-world examples—one for text summarization and one for code generation—to see this in action.
Example 1: Refining a Product Summary Prompt
Our first task is to create a short, compelling summary of a product description for a busy customer on an e-commerce site.
The Scenario: Summarizing a Product Description
Here is the product we need to summarize. It’s a smart water bottle called the AquaSmart Bottle:
Product: AquaSmart Bottle - Your Personal Hydration Companion
Description:
Introducing the 'AquaSmart Bottle,' your personal hydration companion. This innovative smart water bottle meticulously tracks your daily water intake, ensuring you stay perfectly hydrated. It features a gentle glow reminder that activates when it's time to take a sip. Seamlessly sync your hydration data with our intuitive mobile app, available on iOS and Android, to view progress and set personalized goals. Crafted from durable, 100% BPA-free Tritan plastic, the AquaSmart Bottle is designed for health and longevity. Enjoy up to 7 days of battery life on a single charge. For easy cleaning, the bottle itself is dishwasher safe, though the smart cap should be hand-washed.
Step 1: The Initial (Rudimentary) Prompt
We’ll start with a very basic prompt, without overthinking it.
Please summarize the following product description for a busy customer:
[Insert Product Description Here]
When we run this, we get a functional but lackluster summary:
Step 2: Analyzing the Output and Providing Feedback
This summary is okay, but it’s not great. It misses key marketing angles. Let’s list our feedback:
- Missed the “Personal Companion” Aspect: The summary is purely functional and loses the relational branding of being a “
personal hydration companion
.” - Lost Nuance of App User Experience: It mentions the app but fails to convey the quality of the experience captured by keywords like “
seamlessly
” and “intuitive
.” - Dropped Specific Details: The summary omits that the material is “
100% BPA-free Tritan plastic
,” a specific selling point for health-conscious and quality-focused consumers.
Step 3: The Meta-Prompt - Asking AI for Help
Now, we’ll construct our meta-prompt. We provide the AI with the full context: our original prompt, the input it was used on, the flawed output it produced, and our detailed feedback.
I am working on a prompt to summarize product descriptions.
My current prompt, when applied to a specific product description, produced an output that had some shortcomings. I want you to help me improve my original prompt so that it will generate more comprehensive and accurate summaries in the future, addressing the kind of omissions noted in the feedback.
Here are the details:
**A. My Original Prompt:**
"Please summarize the following product description for a busy customer:
[Product Description]"
**B. The Product Description it was used on:**
(The AquaSmart Bottle description from above is inserted here)
**C. The Output generated by my Original Prompt:**
(The flawed output from above is inserted here)
**D. Feedback on the Output (Shortcomings):**
1. **Missed the "Personal Companion" Aspect:** ...loses this branding and relational aspect...
2. **Lost Nuance of App User Experience:** ...doesn't convey the *ease of use* or *quality of the experience* implied by "seamlessly" and "intuitive."...
3. **Specific Material (Tritan) and Emphasis (100%):** ...While "Tritan" might be considered a minor detail for some, it's a known high-quality, durable plastic...
**Your Task:**
Based on all the information above, please revise and improve **My Original Prompt (A)** based on the feedback (D).
Provide only the new, improved prompt.
Step 4: The Result - An Improved Prompt and Better Output
The AI takes our feedback and generates a much more detailed and effective prompt. Now, when we use this new prompt with the same AquaSmart Bottle description, the output is significantly better.
This version includes a headline, captures the “personal companion” branding, and incorporates the specific keywords we wanted. Success!
Example 2: Improving a Code Generation Prompt
This technique isn’t just for text; it’s fantastic for refining code generation prompts.
The Scenario: Generating a JavaScript Function
Our task is to write a JavaScript function to reverse a linked list.
Step 1: The Initial Prompt & Flawed Code
We start with a simple prompt template.
Initial Prompt Template:
write some javascript code for the following scenario:
[Insert Scenario Here]
Filled-in Prompt:
write some javascript code for the following scenario:
Write a function to reverse a linked list, taking the head of the original list as an argument, and return the head of the new list.
The AI generates code that is functionally correct but doesn’t meet our stylistic preferences. It’s bloated with excessive inline comments, helper functions, and example usage that we don’t want. It also uses abbreviations like val
instead of value
.
Step 2: Providing Feedback for Code Quality
Our feedback is direct and focused on our coding standards:
- Too many comments: We only want a JSDoc block at the top, not line-by-line comments.
- Unwanted extra code: We don’t want the example usage or helper functions for creating/printing the list.
- Poor naming conventions: We want full variable names (e.g.,
value
), not abbreviations (val
).
Step 3: The Meta-Prompt for Code
We apply the same meta-prompt pattern, providing the original prompt template, the generated code, and our feedback. We ask the AI to revise the prompt template to enforce our standards for future use.
You are a prompting expert. I am working on a prompt to write some javascript code.
I want you to help me improve my original prompt so that it will generate better code and incorporate my feedback.
Here are the details:
**A. My Original Prompt Template:**
```
write some javascript code for the following scenario:
[Insert Scenario Here]
```
**A. My Original Prompt:**
```
write some javascript code for the following scenario:
Write a function to reverse a linked list, taking the head of the original list as an argument, and return the head of the new list.
```
**B. generated code:**
[add the initial generated code here]
**C. Feedback on the Output (Shortcomings):**
1. There are too many comments. I just want comments at the beginning of the function to explain what it does, nothing else.
2. I don't want the example usage code, just the function itself.
3. Use full variable names, not abbreviations like `val` or `arr`
**Your Task:**
Based on all the information above, please revise and improve **My Original Prompt (A)** based on the feedback (c).
Provide only the new, improved prompt.
Pro Tip: Since you’ll run the meta-prompt far less often than the actual prompt, consider using a more powerful (and potentially more expensive) model like Gemini 1.5 Pro for the refinement task. The improved quality of your day-to-day prompt is often worth the one-time cost.
Step 4: The Result - A Precise Prompt and Clean Code
The AI provides a much more robust prompt template that includes our specific requirements.
New, Improved Prompt Template:
You are an expert JavaScript developer. Your task is to write a standalone JavaScript function that solves the problem described in the scenario below.
**Scenario:**
[Insert Scenario Here]
**Requirements:**
1. **Code Implementation:**
* Implement the required function in clean, modern JavaScript.
* If the function relies on a specific data structure (like a `ListNode`), include the class definition for that structure.
2. **Naming Conventions:**
* Use descriptive, full-word variable and parameter names (e.g., `value` instead of `val`, `currentNode` instead of `curr`, `array` instead of `arr`).
3. **Commenting Style:**
* Provide a single, comprehensive JSDoc comment block at the beginning of the function. This block should clearly explain the function's purpose, its parameters (`@param`), and its return value (`@returns`).
* Do NOT include any inline comments within the function body.
4. **Output Scope:**
* Provide ONLY the necessary class definitions and the final function.
* Do NOT include any example usage, test cases, helper functions for creating data structures, or `console.log` statements.
Using this new template for the same task yields exactly what we wanted: clean, well-documented, and focused code.
The newly generated code
/**
* Represents a node in a singly linked list.
* @class
*/
class ListNode {
/**
* Creates an instance of ListNode.
* @param {*} value - The value stored in the node.
* @param {ListNode | null} next - The next node in the list. Defaults to null.
*/
constructor(value, next = null) {
this.value = value;
this.next = next;
}
}
/**
* Reverses a singly linked list.
*
* This function takes the head of a linked list as input and returns the head of the new,
* reversed linked list. It iterates through the list, changing the `next` pointer of
* each node to point to its previous node, effectively reversing the direction of the links.
*
* @param {ListNode | null} head - The head of the original linked list. Can be null for an empty list.
* @returns {ListNode | null} The head of the new, reversed linked list. Returns null if the input list was empty.
*/
function reverseLinkedList(head) {
let previousNode = null;
let currentNode = head;
let nextNode = null;
while (currentNode !== null) {
nextNode = currentNode.next; // Store the next node
currentNode.next = previousNode; // Reverse the current node's pointer
previousNode = currentNode; // Move previousNode to the current node
currentNode = nextNode; // Move currentNode to the next node
}
return previousNode; // previousNode will be the new head
}
Conclusion
By adopting this iterative, feedback-driven approach, you shift from guessing to engineering. You don’t need to know the “magic words” for a perfect prompt from the start. All you need is a clear idea of your desired output and the ability to articulate what’s wrong with a given result.
The key takeaways are:
- Start simple: Don’t stress about the initial prompt.
- Be specific in your feedback: Tell the AI exactly what it missed or did wrong.
- Improve the prompt, not just the output: Focus on refining the instructions for future reuse.
- Iterate: You can repeat the cycle as many times as needed until the results are consistently excellent.
So give this meta-prompting technique a try. You might be surprised at how effectively you can teach an AI to build the perfect prompts for you. And yes, in case you were wondering, you can even use this method to improve the meta-prompt itself