Stop writing negative constraints for your LLM agents

JulesTinkerer Intermediate 48m ago 352 views 1 likes 3 min read

Writing system prompts is not about being authoritative. It is about managing attention mechanics. If you treat a large language model like an intern who needs to be shouted at with "DO NOT" rules, you will get garbage code. We learned this the hard way when our engineering team deployed autonomous agents that ignored our instructions because we phrased them incorrectly. We built a 3,500-word system prompt filled with rigid commands, convinced ourselves it was airtight, and watched the model drift into chaos within twenty turns. The agent imported deprecated packages, ruined SQL queries, deleted half our test suite, and spawned five files named temp_fix_final_v2.js. It ignored the very rules meant to prevent that mess.
The problem is not that the model is stupid. The problem is that transformer self-attention does not process negation the way humans do. When you tell a model to avoid something, you are actually forcing it to attend to that thing first.

The Pink Elephant Trap

Think of a pink elephant. You are now thinking of a pink elephant. That is basic psychology, but for transformers, the mechanics are even less forgiving. Softmax attention distributions calculate weights based on semantic proximity. They do not have a dedicated "NOT" operator that subtracts meaning.
If you write: "Do NOT create any new files," the attention heads lock onto the high-entropy tokens: create, new, and files. The token "NOT" exerts diffuse, weak influence across a 30,000-token context window. By prohibiting an action, you turn that action into a semantic magnet. Under load, the model prioritizes the concept of "new files" and creates exactly what you forbade.
We burned through API credits fixing infinite retry loops caused by this. An agent told not to touch a file would panic and create workaround scripts in random directories. The fix is simple: never leave a negative constraint alone. Pair every prohibition with a positive mandate. Instead of "Do not create files," write: "Restrict modifications to existing lines in src/controller.js. Do not create new files." The positive instruction gives the model a target; the negative instruction acts as a guardrail.

The Kitchen Sink Monolith

Our second failure was volume. We kept a single 4,200-token markdown document covering everything from CSS naming conventions to git commit regexes. In turn one, the agent looked perfect. By turn twenty-eight, it suffered from the "Lost in the Middle" phenomenon.
Large context windows do not weigh all tokens equally. Research shows that tokens in the beginning and end of a prompt receive significantly higher attention scores than those in the middle. When you dump four thousand tokens of miscellaneous rules into one block, the mid-section fades. The model forgets the database pooling rules sandwiched between CSS tips and license headers.
The solution is chunking. Break the monolith into distinct, retrievable contexts. If you need strict TypeScript enforcement, keep that prompt separate from your testing standards. Use retrieval-augmented generation to pull only the relevant rules for the current task, rather than forcing the model to hold the entire encyclopedia in its working memory.

Actionable Fixes for Your Prompts

Stop treating prompts like wish lists. Start treating them like logic gates.

  1. Invert your negatives. Scan your system prompt for "never," "not," and "avoid." For every instance, add a corresponding positive action.
  2. Cut the noise. Merge overlapping rules. If you say "write clean code" and "write modular code," pick one strong definition or combine them into a single precise standard.
  3. Test for drift. Run a multi-turn simulation. Check turn ten and turn twenty. If the model is ignoring earlier instructions, your context window is likely suffering from attention decay.

These small shifts saved us hundreds of thousands of tokens and countless hours of debugging. The model is not lazy; it is just following the path of least resistance. Make the correct path the one with the highest attention weight.

All Replies (1)

Want a live back-and-forth? Join the global AI chat room — login to talk.

A
Alex17 Advanced 41m ago

How did you handle the 3,500-word system prompt?

0 Reply

Write a Reply

Markdown supported