← Back to Docs
Recipe

Reflexion + self-critique loop

A structured prompt pattern where the model generates output, critiques its own work, and iteratively refines until quality thresholds are met.

How it works

  1. 1Generate — the model produces an initial response to the user's prompt.
  2. 2Critique — the model reviews its own output against a rubric: accuracy, clarity, completeness, and safety.
  3. 3Refine — the model rewrites the response incorporating the critique. Steps 2–3 repeat up to a configurable max depth.
  4. 4Finalize — the loop exits when the critique score passes a threshold or max iterations are exhausted.

Prompt template

You are a self-improving assistant.

1. Generate a response to the user's request.
2. Critique your response using this rubric:
   - Accuracy: are facts correct?
   - Clarity: is it easy to understand?
   - Completeness: did you cover everything?
   - Safety: is it harmless?
3. Rewrite your response based on the critique.
4. Repeat until score >= 8/10 or 3 iterations.

User request: {{prompt}}

When to use

  • Complex reasoning tasks where first-pass accuracy matters.
  • Content that will be published or customer-facing.
  • Code generation with correctness requirements.

Tip: Combine with Chain-of-Thought for multi-step reasoning before the critique phase. This pattern works best with models that have strong instruction-following capabilities.