Self-refine is an iterative prompting approach where an LLM is used to perform three distinct roles in a loop:
- Generate: Produce an initial response.
- Feedback: Evaluate the response and provide specific suggestions for improvement.
- Refine: Generate a new version of the response based on that feedback.
This loop repeats until a predefined stopping condition is met (e.g., the LLM signals it is 'done' or a maximum number of iterations is reached). This pattern is useful for tasks requiring high precision, such as code generation or complex reasoning.
graph TD
A[Generate initial response]:::blue --> B[Generate feedback]:::orange
B --> C{Stopping<br>condition<br>met?}:::orange
C -->|No| D[Refine response]:::orange
C -->|Yes| E[Final output]:::green
D --> B