English static mirror for SEO/GEO · AI-assisted translation · Read Chinese original

Why More Rules Make AI Write Worse Code: Understanding Constraint Decay

Forum topic · QianXun · 2026-05-09

Summary

A Chinese forum post discusses "Constraint Decay", a phenomenon described in the paper "Constraint Decay: The Fragility of LLM Agents in Backend Code Generation" by Francesco Dente. The post explains that as developers add engineering constraints to AI coding agents—such as architectural patterns, specific libraries, or database requirements—the AI's success rate on core business logic drops sharply. Reported experimental data shows even the strongest model (GPT-5.2) loses an average of 30 points in assertion pass rate when moving from simple tasks to fully-constrained tasks, while weaker models can fail completely. The main failure point is the data persistence layer, where models hallucinate on ORM details like session management and relation queries. AI also performs worse in convention-over-configuration frameworks (Django, FastAPI) than simpler ones (Flask). The author argues current AI is a good tactical executor but not a true architect, and developers should audit their own constraint lists before blaming the model.

Imagine you've invited a Michelin-starred chef to cook at your home.

You say: "Chef, I'd like some egg fried rice." A few minutes later, a golden, perfectly separated plate of fried rice arrives. Delicious!

The next day, you want fried rice again—but this time you add some "rules":

1. "You must use this cast-iron wok, not the non-stick pan." 2. "You must stir-fry from 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 whole time."

What happens? The chef, distracted by these bizarre, fussy restrictions, forgets to turn off the stove and serves you a burnt, unevenly salted mess.

In the world of large language models (LLMs), 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 (architecture patterns, specific libraries, database constraints), the AI's success rate at solving the core business problem falls off a cliff.

What Is Constraint Decay?

The paper's author, Francesco Dente, found that today's AI agents perform excellently on "naked" tasks. Ask for a simple registration endpoint and it flies through it.

But once you put "engineering shackles" on it, such as:

  • "Use the Clean Architecture pattern."
  • "The database must be PostgreSQL, accessed via the SQLAlchemy 2.0 async driver."
  • "All entities must go through a DTO transformation layer."
The AI performs like a dancer with bound hands and feet.

Experimental data shows that even on the strongest model, GPT-5.2, switching from "simple tasks" to "fully-constrained tasks" causes the assertion pass rate to drop by an average of 30 points. Weaker models can fall to zero.

Why Does AI Struggle With Rules?

Let's break down the mental logic in Feynman style:

1. Context Window Saturated by Non-Functional Requirements

Writing code consumes "attention." When you ask the AI to get the logic right *and* follow complex architectural style, its attention is heavily diverted to these formalities. It's like solving a hard calculus problem while also composing it as a regulated verse poem—your math will likely fall apart.

2. The Data Layer Is AI's Nightmare

The paper found the biggest failures occur in the data persistence layer.

AI often writes logically coherent code, but when handling subtle ORM rules (session management, relation queries, boundary isolation between layers), it hallucinates frequently. It produces 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 background context in mind, and one slip triggers a taboo.

Why This Paper Matters

Previously, we judged AI-written code by one question: "Does it run?"

But this paper reminds us: in real industry settings, "it runs" is only the minimum bar. Whether the code meets team engineering standards and architectural conventions matters just as much.

If AI writes functionally correct code that shoves database queries directly into the presentation layer, that code is "debt" for the project.

To summarize:

Current AI is an excellent "tactical executor," but not yet a qualified "architect."

Every constraint you give it adds a brick to its mental balance scale. Once there are enough bricks, the scale tips completely.

So the next time AI writes terrible code, don't rush to call it stupid. First check whether you're like that eccentric diner—loading the chef with unnecessary "left-hand-in-pocket fried rice" rules.

True intelligence isn't just solving problems—it's solving them elegantly under heavy shackles. Clearly, AI still has a long way to go.

Tags

#llm#ai-coding#constraint-decay#software-architecture#code-generation#backend-development#orm#ai-agents

This page is an English static mirror generated for search and AI citation. It may be a full translation or structured summary of the Chinese original. Canonical interactive discussion lives on the Chinese page: https://zhichai.net/topic/177619675