Prompting Strategies and Tips › Iteration: Your Secret Weapon
AI Agent HandbookAll chapters Prompting Strategies and Tips › Iteration: Your Secret WeaponOne section · Sections in this chapter4 / 10 ↓
Here's something that might surprise you: even experienced practitioners rarely get the perfect prompt on the first try. Prompting is an iterative process. You start with something reasonable, see what happens, and then refine based on the results.
This isn't a flaw in the system. It's actually a feature. Because you can quickly test different prompts and see results, you can rapidly improve your approach. Think of it like adjusting a recipe while cooking. You taste, adjust the seasoning, taste again, and keep refining until it's right.
The Iteration Cycle
Here's a simple process that works well:
-
Start with a clear, simple prompt: Don't overthink it. Write what you want in plain language.
-
Run it and examine the output: Does it do what you wanted? Where does it fall short?
-
Identify the gap: Is the output too vague? Too formal? Missing key information? Getting the format wrong?
-
Adjust one thing: Add more specificity, include an example, change the role, or modify the instructions. Change one element at a time so you know what made the difference.
-
Test again: See if the adjustment helped. If not, try a different approach.
Example: Refining a Prompt
Let's walk through a real iteration process. Suppose you're building a feature for your personal assistant to summarize articles.
First attempt:
Summarize this article.Result: The summary is too long and includes minor details.
Second attempt:
Summarize this article in 3 sentences, focusing on the main points.Result: Better, but the tone is too formal for your needs.
Third attempt:
You are a friendly assistant helping someone catch up on news.
Summarize this article in 3 sentences, focusing on the main points.
Use a conversational tone.Result: Much better! The summary is concise, focused, and easy to read.
Notice how each iteration addressed a specific issue. We didn't try to fix everything at once. This methodical approach helps you understand what works and why.
Example (GPT-5)
Here's how you might implement this iteration in code:
import os
from openai import OpenAI
client = OpenAI(api_key=os.getenv("OPENAI_API_KEY"))
article = """[Your article text here...]"""
## Version 1: Basic prompt
## GPT-5 is ideal for summarization tasks with clear instructions
def summarize_v1(text):
response = client.chat.completions.create(
model="gpt-5",
messages=[
{"role": "user", "content": f"Summarize this article:\n\n{text}"}
],
)
return response.choices[0].message.content
## Version 2: Add constraints
def summarize_v2(text):
response = client.chat.completions.create(
model="gpt-5",
messages=[
{
"role": "user",
"content": f"Summarize this article in 3 sentences, focusing on the main points:\n\n{text}",
}
],
)
return response.choices[0].message.content
## Version 3: Add role and tone
def summarize_v3(text):
response = client.chat.completions.create(
model="gpt-5",
messages=[
{
"role": "system",
"content": "You are a friendly assistant helping someone catch up on news.",
},
{
"role": "user",
"content": f"Summarize this article in 3 sentences, focusing on the main points. Use a conversational tone:\n\n{text}",
},
],
)
return response.choices[0].message.content
## Test each version
print("Version 1:", summarize_v1(article))
print("\nVersion 2:", summarize_v2(article))
print("\nVersion 3:", summarize_v3(article))Version 1: I don’t see the article text. Please paste the article (or a shareable link plus the key passages), and tell me: - Desired length: 1–2 sentence TL;DR, 5-bullet summary, or a short paragraph? - Audience: general reader, expert, or executive? - Any focus: key findings, methods, implications, controversies, or stats/quotes to retain? - Do you want a suggested headline? If the article is long, you can paste it in parts—I’ll summarize as we go.
Version 2: I don’t have the article text yet. Please paste the article (or share a link), and I’ll summarize it in exactly 3 sentences focusing on the main points. If it’s long, you can paste it in chunks, and tell me if there’s any specific angle or audience you want prioritized.
Version 3: I don’t see the article text yet. Please paste the article or share a link, and I’ll give you a 3‑sentence, conversational summary focused on the main points. If it’s paywalled, you can paste the key sections or a screenshot, and I’ll work from that.
By keeping different versions, you can compare results and see which approach works best. In real development, you might save successful prompts in a file or database so you can reuse them later.