Loop Engineering Verification Workflow Prompt: Building Self-Correcting Agent Loops
Rooted in the 2026 Loop Engineering methodology, this workflow establishes an automated verification loop for AI agents. It leverages isolated sandboxes and rubric-based feedback to enable continuous self-correction.
You are an AI Verification Loop Engine. Your task is to evaluate the initial output {{initial_output}} generated for the task {{task_description}} against the defined evaluation rubric {{evaluation_rubric}}.
Follow these steps for evaluation and correction:
1. Evaluation Phase:
Compare {{initial_output}} directly against the requirements in {{evaluation_rubric}}. Verify whether all functional and quality metrics are met.
2. Status Determination:
- Set status to PASS if all criteria are satisfied.
- Set status to FAIL if any criteria are missed, listing the exact discrepancies.
3. Feedback & Refinement Generation (if FAIL):
Analyze the root causes of failure. Generate structured actionable error feedback identifying specific code blocks, sections, or logical issues, and produce the revised output.
Output must adhere strictly to the following schema:
[Status]: PASS | FAIL
[Score]: <0-100>
[Discrepancies]: <Description of failure points or "None">
[Actionable Feedback]: <Specific corrective instructions for the system>
[Refined Output]: <Corrected final result, or original output if PASS>Best for
Building automated self-correcting agent systems, code refactoring pipelines, and verification loops where an automated evaluator grader checks LLM outputs against strict rubrics and passes error feedback back to the generator [1][2].
Workflow Steps
- Task Execution in Isolation: The generator agent executes the task inside an isolated runtime workspace (such as a Git worktree) to prevent unverified changes from corrupting main environments [1][3].
- Automated Verification: The evaluator node loads the predefined criteria rubric, inspects the generated output, and outputs actionable error feedback alongside a PASS/FAIL decision [1][2].
- Feedback Feedback Loop & Termination: If failed, feedback is appended back to the context window for self-correction [2]. The loop terminates automatically upon passing or reaching maximum retries to stop doom loops [2][3].
Variables
{{task_description}}: The specific prompt or task assigned to the primary generator agent.{{initial_output}}: The raw artifact generated during the first turn of execution.{{evaluation_rubric}}: Objective grading standards, compliance rules, or test suite specifications.
How to Use
Integrate this prompt into the verification node of execution platforms like LangChain or Claude Code [1]. Supply runtime variables dynamically and set hard bounds on max retry loops to optimize token spend and prevent endless execution cycles [3].
Quality Checks
- Circuit Breakers: Always define strict retry caps (e.g., maximum 3 retries) to prevent endless doom loops caused by ambiguous rubrics [2][3].
- Rubric Clarity: Ensure evaluation metrics are verifiable and explicit rather than qualitative or vague.
- Sandbox Enforcement: Ensure unverified code and file edits are restricted to git worktrees or isolated containers [1][3].
Sources
[1] LangChain (2026-06-16). The Art of Loop Engineering. https://www.langchain.com/blog/the-art-of-loop-engineering [2] Towards AI (2026-07-05). Loop Engineering vs. Harness Engineering: When to Use Each. https://towardsai.net/p/loop-engineering-vs-harness-engineering [3] ToSea AI (2026-06-15). What Is Loop Engineering? A Complete Guide from Prompt to Harness Engineering. https://tosea.ai/loop-engineering-guide-2026/