The Generate-reflect-refine loop
Professional writers do not publish their first draft. They write, review, and revise. Iterative refinement applies the same idea to LLM output: Generate a draft, have the model critique it, then refine based on the critique. This 3-step loop consistently produces better results than a single prompt.
The Generate-Reflect-Refine loop: 1. Generate: "Write a luxury restaurant review for La Maison." 2. Reflect: "You are a senior editor. Critique this review for: sensory details, vocabulary variety, and balanced tone. List specific improvements." 3. Refine: "Rewrite the review incorporating this feedback: [critique]" The key insight is using a different persona for the critique step. A "Senior Editor" catches problems that the "Writer" persona misses.
Switching personas forces the model to evaluate from a different perspective. A "writer" persona tends to defend its own work, while an "editor" persona is primed to find flaws. This role separation mimics real-world writing workflows where authors and editors are different people, and it produces genuinely better critique.
# Step 1: Generate the initial draft
draft = get_completion(
"Write a 3-sentence restaurant review for La Maison, "
"a French fine dining restaurant."
)
print("Draft:", draft)The Generate step produces a first draft. It will not be perfect, and that is intentional. The point is to get raw material that the next step can improve.
Now we switch personas. Instead of a "writer," we use a "senior food critic and editor" to critique the draft. Using a different persona activates different evaluation criteria, and the editor catches issues the writer persona would miss.
# Step 2: Reflect (different persona critiques the draft)
critique = get_completion(
f"You are a senior food critic and editor.\n"
f"Critique this review for: sensory detail, vocabulary, "
f"and balanced tone. List specific improvements.\n\n"
f"Review: {draft}",
)
print("Critique:", critique)The Reflect step produces specific, actionable feedback. The critique lists what to improve, not a vague "make it better."
With the critique in hand, we now feed both the original draft and the specific feedback into a final Refine step. This is where the loop pays off because the model has concrete issues to address rather than vaguely trying to "do better."
# Step 3: Refine by rewriting with the feedback
final = get_completion(
f"Rewrite this restaurant review incorporating the feedback.\n\n"
f"Original: {draft}\n\n"
f"Feedback: {critique}"
)
print("Final:", final)The Refine step combines the original draft with the critique to produce an improved version. This final output is consistently better than a single-shot prompt.
Quiz: Quiz
Loading practice…