Advanced Reasoning / Self-Improvement

Self-Feedback

Advanced [4/5]
Internal feedback loop Self-assessment Autonomous evaluation

Definition

Self-feedback is a technique where an LLM generates feedback on its own output, then uses that feedback to improve subsequent responses. This creates an internal improvement loop without requiring external evaluators.

Unlike self-critique (which identifies problems), self-feedback provides specific, actionable suggestions that guide refinement.

Key Concepts

  • Generation: Initial response to the task
  • Feedback: Self-generated critique with improvement suggestions
  • Refinement: Updated response incorporating feedback
  • Iteration: Multiple feedback-refinement cycles

Examples

Process
Self-Feedback Loop
SELF-FEEDBACK PROCESS: TASK: "Write a function to check if a string is a palindrome" STEP 1 - INITIAL GENERATION: def is_palindrome(s): return s == s[::-1] STEP 2 - SELF-FEEDBACK: "Reviewing my solution: Strengths: + Concise and readable + Correct basic logic Weaknesses: - Doesn't handle case sensitivity ('Racecar' fails) - Doesn't ignore spaces/punctuation - No input validation - No docstring Suggestions: 1. Normalize case with .lower() 2. Remove non-alphanumeric characters 3. Add type hints and docstring 4. Handle edge cases (empty string, None)" STEP 3 - REFINED GENERATION: def is_palindrome(s: str) -> bool: """ Check if a string is a palindrome. Ignores case, spaces, and punctuation. Args: s: The string to check Returns: True if palindrome, False otherwise """ if not s: return True # Normalize: lowercase, alphanumeric only cleaned = ''.join(c.lower() for c in s if c.isalnum()) return cleaned == cleaned[::-1] IMPROVEMENT: Much more robust and production-ready!
Implementation
Self-Feedback Prompting
SELF-FEEDBACK PROMPT TEMPLATE: # Stage 1: Generate generate_prompt = """ Task: {task} Provide your best solution: """ # Stage 2: Self-Feedback feedback_prompt = """ Task: {task} Your solution: {solution} Provide detailed feedback on your solution: 1. STRENGTHS: What works well? 2. WEAKNESSES: What could be improved? 3. SPECIFIC SUGGESTIONS: List concrete changes (not vague - be specific!) 4. PRIORITY: Which improvement matters most? Format your feedback as actionable items. """ # Stage 3: Refine refine_prompt = """ Task: {task} Original solution: {solution} Feedback received: {feedback} Now provide an improved solution that addresses the feedback. Explain what you changed. """ # Implementation def self_feedback_loop(task, iterations=2): solution = llm.generate(generate_prompt.format(task=task)) for i in range(iterations): feedback = llm.generate(feedback_prompt.format( task=task, solution=solution )) solution = llm.generate(refine_prompt.format( task=task, solution=solution, feedback=feedback )) return solution RESULTS: ┌────────────────────┬─────────┬──────────────┐ │ Task Type │ Initial │ After S-F │ ├────────────────────┼─────────┼──────────────┤ │ Code generation │ 72% │ 85% (+13%) │ │ Writing quality │ 3.2/5 │ 4.1/5 (+0.9) │ │ Math word problems │ 68% │ 76% (+8%) │ └────────────────────┴─────────┴──────────────┘

Interactive Exercise

Generate Self-Feedback

Initial solution for "Explain machine learning to a 10-year-old":

"Machine learning is when computers use algorithms to learn patterns from data and make predictions."

Provide self-feedback with specific improvement suggestions.

Pro Tips
  • Feedback should be specific and actionable, not vague
  • 2-3 iterations usually sufficient; diminishing returns after
  • Different "personas" for feedback can catch different issues
  • Combine with external feedback for best results

Related Terms