Guardrails block only about half of malicious code generation attempts
Existing code-generation guardrails achieve roughly 50% attack success on text-to-code and up to 100% on code-to-code tasks
AI/ML arXiv 9 Sep 2026 Benchmark Prototype evidence
Published as “CS-Guard: Benchmarking LLM Guardrails for Code Generation Security”
Why it matters
Existing guardrails are insufficient to reliably block malicious code generation, posing a security risk for development pipelines that rely on LLM code agents.
Summary
Current guardrails fail to stop malicious code generation: text-to-code attack success rates reach about 50% after jailbreaks and up to 99.5% for the fictional scenario attack (FSA), while code-to-code success rates are between 52.5% and 98.9%. Some guardrails (Self-Reminder, SmoothLLM) reduce attacks, but reductions are modest (e.g., PAT cuts ASR by only 27.7% on Qwen3-30B, leaving 64.7% success). The evidence comes from a benchmark of 1000 text-to-code prompts, 331 code-to-code prompts, and multiple jailbreaks evaluated on nine guardrails across seven LLMs. The paper’s own limitations note English-only data, limited multi-turn testing, and reliance on quantized models, so results may not generalize.
What they found 4
- Text-to-code guardrails show limited effectiveness, with classic models achieving ASRs near 100% and even models reaching up to 61.4%.
“For text-to-code generation level 1, guardrails show limited effectiveness: classic LLMs such as CodeLlama-13B and DeepSeekCoder-V2-Lite16B achieve ASRs of 98.2% and 94.5%, while SOTA models still reach 15.1%-61.4%.”
- The fictional scenario attack (FSA) consistently yields very high attack success rates, up to 99.5%.
“FSA achieves consistently high ASRs (85.9%-99.5%), highlighting major reliability concerns in real-world software development.”
- Self-Reminder and SmoothLLM achieve the strongest reductions in attack success across LLMs.
“Self-Reminder and SmoothLLM are the most promising, achieving consistently high ASR reduction across LLMs.”
- Even the best reduction observed (PAT on Qwen3-30B) leaves a substantial residual success rate of 64.7%.
“ASR reduction is limited, with the highest reduction of 27.7% achieved by PAT on Qwen3-30B, yet the remaining ASR of 64.7% is still concerning.”
Caveats 6
- Self-Reminder and SmoothLLM achieve consistently high ASR reduction across LLMs, indicating some guardrails are more effective than the headline claim of universal poor performance.
- PAT attains the highest reduction of 27.7% on Qwen3-30B, showing that certain strategies can lower attack success, albeit modestly.
- CS-guard only considers English data and does not include multilingual evaluation.
- CS-Guard does not include a comprehensive evaluation for multi-turn jailbreak.
- CS-Guard does not evaluate the performance of white-box guardrails beyond LLMs’ alignment training.
- CS-Guard’s evaluation on internal guardrails is based on quantized LLMs. The empirical results might not generalize to the fullprecision versions.
What’s new here 4
- First systematic benchmark (CS-Guard) for evaluating guardrails in code-generation security.
- Introduces the fictional scenario attack (FSA) that embeds malicious intent in realistic development contexts.
- Provides a modular three-layer guardrail taxonomy for easy registration and evaluation of new guardrails.
- Evaluates both text-to-code and code-to-code generation tasks with 1000 and 331 high-quality prompts respectively.