Static-analysis alerts injected mid-generation: DeepSeek-V4.1-flash lifts functional-and-secure programs on RiskyPy from 52.5% to 64.4% at 1.7 times the baseline tokens
Synopsis
Static analyzers are cheap and widely deployed, but they had only been placed inside multi-round repair loops, where intermediate steps add cost and make the alert's own effect hard to isolate. Two strategies hand the alert to the model during generation, as a code comment or in the user message, rolling back to before the flagged line and resuming. Across three models and three Python benchmarks, this in-generation guidance costs 0.9 to 1.9 times the baseline's output tokens against up to 24.1 times for iterative approaches; with DeepSeek-V4.1-flash on RiskyPy, it raises the share of functional and secure programs from 52.5% to 64.4%, close to the best iterative approach at 66.2% while using less than a fifth of the tokens.
Interpretation
A static-analysis alert can be handed to the model while code is being generated, rather than only after a whole program exists and enters a multi-round repair loop. PromSec and FDSP both place the analyzer inside an iterative repair loop, so the alert passes through intermediate steps before reaching the model, which is costly and makes the alert's own effect hard to isolate. Across three models and three Python benchmarks, the two in-generation strategies cost 0.9 to 1.9 times the baseline's output tokens, while iterative approaches reach up to 24.1 times.
A harness runs the analyzer each time the model completes a syntactically valid line; when an alert fires, it rolls the code back to before the flagged line and gives the finding to the model before generation resumes. Comment inserts the alert as a code comment after an intent comment, while Steering puts the rule identifier, CWE, message and a pre-written per-rule recommendation at the end of the user message, and only code after the rollback point is regenerated. On RiskyPy, Steering with DeepSeek-V4.1-flash raises the share of functional and secure programs from 52.5% to 64.4% at 1.7 times the baseline tokens; FDSP and Self-Refine reach 66.2% and 63.5% but need 9.8 and 18.3 times the tokens.
Perspective
The results come from three open-weight models (Qwen2.5-Coder-14B, Qwen2.5-72B-Instruct and DeepSeek-V4.1-flash) and three Python benchmarks, covering only black-box generation of single code snippets, with Semgrep and Bandit restricted to a frozen rule set.
The gains are not uniform: no strategy beats the baseline on all three benchmarks, and both Qwen2.5 models often break the program when a fix requires restructuring the code. On SecEvalPlus the analyzers flag at most 5.6% of functional but insecure programs, leaving little for guidance to act on, and when an alert contradicts the task, the models still removed a specification-required network binding in 79 of 83 cases.
