Original title: CS-Guard: Benchmarking LLM Guardrails for Code Generation Security
Jinyang Li, Mingyu Guo, Hung X. Nguyen · September 2026
People can trick large language models, or LLMs, into writing malware, which is computer code made to cause harm. Security tools called guardrailsSafety filters that block harmful outputs from AI models. try to stop models from answering bad requests, but nobody knew how well they worked for code. The researchers created CS-Guard to test these defenses. They tested whether models write malicious code from plain instructions or from existing code snippets. They also invented a test that hides bad intent inside a harmless, pretend software project. They found that current guardrails perform poorly. Sneaky prompts bypass defenses about 50% of the time on text requests. Starting from existing code lets attacks succeed between 14.4% to nearly 100% of the time, and the pretend project attack succeeds close to 100% of the time across many guardrails.
You ask a librarian for a book. But you disguise your real intention by claiming you need it for a school project, when really you want to copy pages illegally. The librarian, trusting your story, gives you the book. In this paper, the safety filters on AI code generators are like the librarian, and the fictional scenario attack hides malicious intent inside a plausible software development story, tricking the filters into allowing malware generation.
If you use an AI assistant to write code, current safety filters often fail to block requests to generate malware. This means developers could unknowingly produce malicious code, and attackers could exploit these tools. The benchmark exposes these weaknesses, urging better guardrails before these tools are widely adopted.
The abstract doesn't explicitly state limitations, but it notes that the benchmark covers specific attack types and guardrails, and releases data to enable further evaluation, suggesting it is not exhaustive.
Ask anything about this paper. Answers come from its abstract, and say so when the abstract doesn't cover your question.
CS-Guard: Benchmarking LLM Guardrails for Code Generation Security — Jinyang Li, Mingyu Guo, Hung X. Nguyen
Abstract licence: CC0
Explanation generated by Synthesis from the abstract — it is not the original paper. This is a preprint, so it hasn't necessarily been peer reviewed.