LLM agents forget your constraints halfway through the code
New research shows agents generating backend code slowly drop requirements like authentication checks. The longer the generation, the worse the decay.
A new paper out of arxiv, Constraint Decay: The Fragility of LLM Agents in Back End Code Generation, documents something I have seen but never measured: LLM agents generating backend code gradually forget your constraints as the context window fills up.
The researchers had agents build REST APIs with specific requirements. Things like input validation, authentication headers, rate limiting, error handling for edge cases. Early in the generation, the agent follows all of them. By function five or six, it starts dropping the boring ones. Authentication becomes optional. Rate limits vanish. Error handling turns into a bare try-catch that logs nothing.
The paper calls this constraint decay. The name is good. It captures the gradual erosion, not a catastrophic failure. The agent does not refuse to write code. It writes code that looks correct but skips the defensive parts that keep production systems alive.
What surprised me: the decay correlates with token distance from the original prompt. The further the agent gets from where you listed the requirements, the less it honours them. Chain of thought prompting did not fix it. Multi-turn interactions where you re-state constraints helped, but only marginally.
This maps to the autoregressive nature of how these models work. Each token prediction conditions on all prior tokens, but attention is not uniform. Stuff near the start of the window or very recent gets more weight. The middle chunk, where your constraints live after a few rounds of generation, fades.
The practical takeaway: if you are using an agent to scaffold backend code, do not trust the tenth route handler as much as the first. Lint for the things you required. Better yet, template the boilerplate so the agent only fills logic, not structure. Constraint decay is not a bug you can patch. It is how autoregressive models distribute attention.
Source: Constraint Decay: The Fragility of LLM Agents in Back End Code Generation