Self-Correcting AI Agents Outperform Single-Shot Prompts in Security Research
A new iterative loop using Gemini 3.5 Flash Lite and OSV API data significantly improves vulnerability analysis accuracy over static single-shot prompts.

Single-shot prompts often fail when tasked with complex software security evaluations. In vulnerability triage, a single prompt pass can produce inconsistent analysis, miss version bounds, or generate inaccurate remediation advice. Recent research demonstrates that shifting from single-pass prompting to an iterative critique-improve-validate loop dramatically enhances the reliability of automated security assessments.
By implementing an autonomous Python agent powered by Google's Gemini 3.5 Flash Lite model, researchers built a self-correcting system designed to ingest real vulnerability records directly from the Open Source Vulnerabilities (OSV) database. Rather than relying on static text or synthetic examples, the system dynamically queries raw JSON payloads from the OSV API using CVE identifiers such as CVE-2021-32804.
How the Iterative Agent Loop Operates
The architecture replaces single-shot instructions with a structured loop where the model analyzes a vulnerability, critiques its previous recommendations, and refines its defense strategy across multiple turns. Gemini 3.5 Flash Lite was chosen for this pipeline because its low latency and fast execution speeds allow multi-turn critique cycles to execute in seconds without inflating operational costs or latency.
To keep the model from running indefinitely, the system defines explicit execution boundaries using Python configuration settings and Pydantic schemas. The maximum iteration count is set to five (MAX_ITERATIONS = 5). Intermediate outputs are validated using a Pydantic IterationRecord model requiring specific fields: critique, refined remediation, and a numerical confidence score ranging from 0.0 to 10.0.
To prevent unnecessary API calls, the agent includes early exit convergence logic. If the model achieves a confidence score of 8.5 or higher after at least two iterations, the pipeline terminates early and marks the record with a status such as VERIFIED_SECURE.
Benchmark Results and Performance Gains
To measure the effectiveness of self-correction, the pipeline evaluated four curated Python package security records: CVE-2021-32804, CVE-2023-32681, CVE-2022-42969, and CVE-2021-29418. The iterative agent was benchmarked against a static single-shot baseline score fixed at 4.5 out of 10.
Across all four vulnerability targets, the self-correcting agent converged within two iterations, consistently reaching remediation quality scores between 9.5 and 9.8. For instance, when evaluating CVE-2021-32804, the agent achieved a score of 9.8 compared to the baseline score of 4.5—yielding an outperformance delta of 5.3 points.
Structured audit logs exported during testing confirmed that early iterations identified underlying flaws, such as root-stripping failure modes in path handling, before refining them into verified mitigations.
What it means for developers
For software engineers and security teams, these findings highlight a shift in how LLMs should be integrated into security pipelines. Relying on single-prompt calls for critical triage tasks introduces structural drift and variance. Enforcing schema validation with tools like Pydantic ensures outputs remain strictly typed and parseable across multi-turn workflows.
Building iterative, multi-turn AI workflows often requires experimenting with different model architectures to strike the right balance between reasoning depth, speed, and cost. Developers can try top AI models cheaply through one API at https://apixoai.online to find the best fit for their specific autonomous loops.
Ultimately, the experiment demonstrates that combining fast models like Gemini 3.5 Flash Lite with structured critique loops and well-defined stopping thresholds turns unpredictable language models into reliable, self-correcting research engines.
Source: Stop Prompting, Start Looping: Building Self-Correcting Vulnerability Research Agents with Gemini 3. — Towards AI. Written by the Apixo team from that report.
One key for Claude, GPT, GLM, DeepSeek and more. Pay per token with crypto.
Get your API key

