Codex Iterative Repair Loop: Review → Repair → Validate Until Broken Code or Docs Pass
An OpenAI Cookbook Codex example that turns 'fixing bugs or outdated examples' into a self-iterating closed loop: first review and list the problems, then make a targeted fix on a copy, then run validation and score it, and if it doesn't pass, feed the remaining issues back in for another round — until everything's green or a cap is hit. Includes three ready-to-use prompt templates.
與其讓 AI「一次寫對」,不如讓它跑一個會自我修正的迴圈:審查→修復→驗證→把沒過的問題餵回去再修。OpenAI Cookbook 這個範例把這套閉環講得很清楚,三段 prompt 直接可改用。
[ Log in to see the full prompt ]Sign up free to see the full prompt, copy it, save it, and join the discussion. Free content unlocks on login; Pro content is a separate subscription.
## What it is / what problem it solves This upgrades 'fixing bugs or outdated code examples' from 'gamble on the AI getting it right in one shot' to 'a self-iterating closed loop.' The original example's specific scenario is maintaining broken, outdated code examples in technical documentation (ones using deprecated models or APIs), but the architecture applies to any 'fix until checks/tests pass' task. The pain point: a single AI repair pass often fixes one thing while breaking another, or claims success without actually passing. Splitting the process into a 'review → repair → validate → feed back and repair again' loop lets it converge on correctness round by round, guided by validation results. ## Why this source is worth using This curates the 'Build iterative repair loops with Codex' example from the **official OpenAI Cookbook**'s codex examples. OpenAI Cookbook is officially maintained by OpenAI and widely cited across the industry; this Codex example demonstrates 'agentic self-correction,' an increasingly important pattern, so both its credibility and practical value are high. ## The core three stages (the essence of the original example) 1. **REVIEW**: examine the target, output structured findings via a JSON schema, but 'don't modify any files' — separating diagnosis from action keeps the initial assessment focused. The original example specifically asks for 'only the most critical few findings,' not an exhaustive list. 2. **REPAIR**: make minimal, targeted changes to 'a copy only,' based on the findings plus the previous round's validation delta, while requiring that 'the original tutorial/business flow be preserved,' and finally report a summary of the changes. 3. **VALIDATE**: actually run the checks, have an LLM judge score each rubric item independently (e.g.: is the API modernized, is the environment reproducible, does the output actually run), attach execution evidence, and compile whatever 'still fails' into a delta to feed into the next round. The key design is **structured handoff between stages**: each round's review findings, repair summary, and validation results get written into a record (e.g. `record.json`), letting you audit afterward 'how it converged' without having to trace through every single edit. ## How to use it 1. Use the three prompts in the full_prompt on the right as the review / repair / validate steps respectively. 2. Fill in `{{ARTIFACT_PATH}}`, `{{BUSINESS_RULES}}` (your preference standards, e.g. specifying model versions, APIs to deprecate), and `{{VALIDATION_CASES}}` (the validation rubric). 3. Chain it into a loop: if validate fails, feed the delta back into repair and rerun, with a `{{MAX_ITERATIONS}}` cap to avoid infinite loops. 4. Repairs must always be made on a 'copy' — only overwrite the original file once it passes validation. ## When to use it Good for tasks with 'clear validation criteria, but that might not be fixed correctly in one pass': fixing broken code examples, upgrading old APIs to new ones, getting a full test suite green, batch-updating a bunch of outdated docs. If a task's correctness can't be automatically validated, this loop's value drops sharply. 📎 Source: the openai/openai-cookbook examples/codex example 'Build_iterative_repair_loops_with_Codex.ipynb' (Copyright © 2025 OpenAI, MIT licensed) — this piece is a rewritten and reorganized version; see the link above for the original notebook.
Suno Engineer's Mindset: 4 Steps to a Song That Doesn't Sound Like AI
A studio engineer's breakdown of Suno's fatal weaknesses (fried vocals, high-frequency artifacts), plus a 4-step DAW workflow and a Suno Studio cleanup prompt.
5 Claude Weekly Workflows That Stuck After 6 Months
Proposal generator / meeting processor / content repurposer / Friday review / shutdown reset — out of 40 I tried, only these 5 survived, each saving 30+ minutes per run.