← Latest papers
💻 computer science

Assessing, Exploiting, and Mitigating Syntactic Robustness Failures in LLM-Based Code Generation

This paper investigates the lack of syntactic robustness in LLM-based code generation when prompts contain mathematically equivalent but syntactically varied formulas, demonstrates how attack strategies exacerbate this failure, and proposes a formula reduction pre-processing technique that significantly improves robustness from 54.05% to 74.42%.

Original authors: Laboni Sarker, Mara Downing, Achintya Desai, Tevfik Bultan

Published 2026-05-12
📖 5 min read🧠 Deep dive

Original authors: Laboni Sarker, Mara Downing, Achintya Desai, Tevfik Bultan

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you have a very smart, but slightly literal-minded robot assistant (a Large Language Model, or LLM) whose job is to write computer code based on your instructions. You tell it, "Build a machine that adds two numbers."

If you say, "Add 2 and 2," it builds the machine.
If you say, "Add 4 and 0," it should build the exact same machine, because mathematically, 2+22+2 is the same as 4+04+0.

This paper asks a simple but critical question: Does this robot understand that these two instructions are the same, even if the words and symbols look different?

The authors call this concept "Syntactic Robustness." Think of it like a person's ability to understand a joke whether it's told in a whisper, a shout, or with a funny accent. If the robot breaks or gets confused just because you changed the style of the math (the syntax) without changing the meaning (the semantics), it lacks robustness.

Here is a breakdown of their findings using everyday analogies:

1. The Problem: The Robot Gets Confused by "Math Speak"

The researchers tested this by taking a math problem and rewriting it in 18 different ways that are all mathematically identical.

  • Original: "The force is F=9.8×a×bF = 9.8 \times a \times b."
  • Rewritten: "The force is F=(9.8×a×b)+0F = (9.8 \times a \times b) + 0." (Adding zero changes nothing in math).
  • Rewritten: "The force is F=(9.8×a×b)×1F = (9.8 \times a \times b) \times 1." (Multiplying by one changes nothing).

They found that the robots (LLMs) are not robust. When the math was rewritten, the robots often wrote completely different, and sometimes broken, code. It's as if the robot thought, "Oh, you added a zero? That must mean you want a different machine!" even though the result should be the same.

2. The "Distance" of Confusion

The researchers measured how "far" they had to twist the math to break the robot.

  • Distance 0: The original, clean math. The robot works okay.
  • Distance 5: The math has been twisted and turned five times (e.g., adding zeros, multiplying by ones, swapping order).
  • Result: As the "distance" increased, the robot's performance crashed. It's like trying to navigate a maze; the more twists and turns you add to the path, the more likely the robot is to get lost, even if the destination is the same.

3. Two Types of Tasks: "Translation" vs. "Reasoning"

The paper discovered the robots handle two types of math requests differently:

  • Translation Prompts: "Here is a formula, just write code that calculates it." (Like a translator copying a sentence). The robots were okay at this.
  • Reasoning Prompts: "Here is a physics problem; figure out the steps to solve it and write the code." (Like a student solving a word problem). The robots were terrible at this when the math was twisted. They couldn't "think" through the logic if the math looked weird.

4. The Attack: Breaking the Robot on Purpose

The researchers acted like hackers to see how easily they could break the robots. They used three strategies:

  • Random Twisting: Just changing the math randomly.
  • Smart Twisting: Using a "cheat sheet" to find the specific changes that confuse the robot the most.
  • The Result: They found that with just a few clever changes (like adding unnecessary zeros or swapping terms), they could make the robot fail almost every time. It's like finding the one specific word in a sentence that makes a translator freeze up.

5. The Solution: "Pre-Processing" (The Simplifier)

Since the robots get confused by complex-looking math, the researchers proposed a fix: Don't feed the robot the messy math; clean it up first.

They built a "pre-processor" (a filter) that sits between you and the robot.

  • You: "Calculate F=(9.8×a×b)+00F = (9.8 \times a \times b) + 0 - 0."
  • Pre-processor: "I see you added and subtracted zero. I'll remove that. Here is the clean version: F=9.8×a×bF = 9.8 \times a \times b."
  • Robot: Receives the clean math and writes the correct code.

The Outcome: This simple step of "cleaning" the math before giving it to the robot boosted its success rate from 54% to 74%. It's like giving a confused student a simplified study guide before the test; they perform much better.

Summary

The paper concludes that while AI code generators are powerful, they are fragile when it comes to math. They get tripped up by simple, harmless changes to how a formula is written. However, if we add a simple "cleaning" step to simplify the math before the AI sees it, we can make them much more reliable.

What the paper does NOT claim:

  • It does not claim this works for all types of AI (only code generation with math).
  • It does not claim this fixes the robot's ability to learn new things (it's just a pre-filter).
  • It does not claim this is a permanent fix for all AI weaknesses, only a specific one regarding math syntax.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →