Imagine hiring a Michelin-starred chef to cook fried rice. The first night, you simply say: "Chef, I'd like some egg fried rice." Minutes later, a perfect plate arrives. Delicious.
The next night, you add a few "rules":
1. "You must use this cast-iron wok, not the non-stick pan." 2. "You must stir-fry strictly left to right, no random tossing." 3. "Salt must be exactly 3.2 grams, added 5 seconds before turning off the heat." 4. "Your left hand must stay in your pocket the entire time."
The result? The chef gets so distracted by these odd, fussy constraints that he forgets to turn off the stove and serves up burnt, unevenly seasoned rice.
In the world of large language models, this is called "Constraint Decay."
In May 2026, a paper titled 《Constraint Decay: The Fragility of LLM Agents in Backend Code Generation》 revealed a painful truth for developers: as you add engineering constraints to AI (architecture patterns, specific libraries, database constraints), its success rate at solving the core business problem falls off a cliff.
What Is "Constraint Decay"?
Paper author Francesco Dente found that today's AI agents excel at "naked" tasks. Ask one to write a simple registration endpoint and it performs brilliantly.
But once you put "engineering shackles" on it, such as:
- "Please use the Clean Architecture pattern."
- "The database must be PostgreSQL, accessed via the SQLAlchemy 2.0 async driver."
- "All entities must pass through a DTO layer."
Experimental data shows that even on the strongest model, GPT-5.2, switching from a "simple task" to a "fully constrained task" causes the code correctness rate (Assertion Pass Rate) to drop by an average of 30 points. Weaker models' success rates can fall to zero outright.
Why Does AI Struggle with "Rules"?
Let's break down the underlying logic the Feynman way:
1. The "brain capacity" (context window) gets consumed by non-functional requirements
Writing code consumes "attention." When you demand the AI both write correct logic *and* follow complex architectural conventions, its attention is diverted to formalism. It's like solving a hard calculus problem while also having to write the answer as a classical regulated verse — your mathematical logic will likely fall apart.2. The "data layer" is AI's nightmare
The paper found AI stumbles hardest at the Data Persistence Layer. AI often writes logically coherent code, but when handling the fine rules of ORM (object-relational mapping) — session management, relation queries, boundary isolation between layers — it frequently "hallucinates." It can produce beautiful-looking code that throws database errors the moment it runs.3. "Conventions" are harder than explicit logic
Interestingly, AI performs better in simple frameworks like Flask, and worse in "convention-over-configuration" frameworks like Django or FastAPI. These frameworks contain lots of "magic" and implicit rules; the AI must hold too much contextual background in mind, and one slip breaks a hidden taboo.Why Does This Paper Matter?
Historically, we judged AI-generated code by one question: "does it run?"
This paper reminds us that in real industry settings, "it runs" is only the minimum bar. Whether the code meets the team's engineering standards and architecture guidelines matters just as much.
If an AI writes functionally correct code but shoves database query logic straight into the presentation layer, that code is pure "liability" for your project.
To summarize:
Today's AI is an excellent "tactical executor," but not yet a qualified "architect."
Every constraint you give it adds a brick to its mental scale. When the bricks pile high enough, the scale tips over completely.
So the next time AI writes terrible code for you, don't rush to call it dumb. First check whether you're like that eccentric diner — piling unnecessary "left hand in pocket" rules onto the chef.
True intelligence is not just solving problems, but solving them gracefully under heavy constraints. Clearly, AI still has a long way to go.