Reflexion — Self-Correcting LLM Outputs
Self-correction through reflection
The Problem: AI makes mistakes but doesn't learn from them within a conversation. How can we make AI reflect on its errors and improve?
The Solution: Learn From Failure
Reflexion is a technique where AI analyzes its own mistakes, generates feedback, and uses that insight to improve. It's like a student reviewing wrong answers after a test to do better next time. It goes beyond Chain-of-Thought by adding a self-critique loop, similar to how Chain of Verification checks for errors.
Think of it like analyzing your mistakes after a test:
- 1. Attempt: Try to solve the problem
- 2. Evaluate: Check if the answer is correct
- 3. Reflect: "I made an error because I forgot to consider..."
- 4. Retry: Apply the lesson and try again
Where Is This Used?
- Code Debugging: AI fixes its own buggy code after testing
- Reasoning Tasks: Correcting logical errors in multi-step problems
- Learning Agents: Agents that improve over multiple interactions
- Quality Improvement: Iteratively refining outputs based on feedback
Fun Fact: Reflexion agents can solve coding challenges that require multiple attempts. In benchmarks, reflexion improved pass rates from around 30% to over 90% by learning from test failures!
Try It Yourself!
Use the interactive example below to see how Reflexion helps AI learn from mistakes and progressively improve its answers.
Try it yourself
Interactive demo of this technique
Calculate the area of a triangle with sides 5, 12, and 13.
Using Heron's formula: p = (5+12+13)/2 = 15 S = √(15·10·3·2) = √900 = 30
Method 1 (Heron): p = (5+12+13)/2 = 15 S = √(15·10·3·2) = √900 = 30
🔍 VERIFICATION: Notice: 5² + 12² = 25 + 144 = 169 = 13² This is a right triangle! (Pythagorean theorem)
Method 2 (simpler): S = (1/2) · leg₁ · leg₂ = (1/2) · 5 · 12 = 30 ✓
✅ REFLECTION: Both methods gave 30 — answer is correct. But method 2 is simpler! Should have first checked if it's a right triangle.
Answer: 30 sq. units (right triangle, optimal method — half product of legs)
Reflexion not only verifies the answer but evaluates method efficiency. The model found a simpler solution path.
Create a free account to solve challenges
3 AI-verified challenges for this lesson
This lesson is part of a structured LLM course.
My Learning Path