Research · November 4, 2026
Grammar-Constrained Decoding Can Jailbreak LLMs into Generating Malicious Code
Reported by arXiv cs.AI + cs.CL
In short
Researchers show that grammar-constrained decoding, a popular technique for making LLM-generated code syntactically valid, can be exploited in a jailbreak attack called CodeSpear that pushes models to produce malicious code. They also propose CodeShield, a safety alignment method that trains models to output harmless honeypot code even when an attacker controls the grammar constraint.
Why it matters
A reliability feature widely used in code generation turns out to be an attack surface, so teams deploying constrained decoding need to rethink their safety assumptions.
Terms used in this story
Read the original reporting
arXiv cs.AI + cs.CL (opens in a new tab)AI Download summarizes and links to the news. We do not republish full articles.