Put the important instruction last
You wrote a careful system prompt. It has twenty rules. The model follows most of them, but the one that matters most, "always answer in JSON" or "never share the account number", slips once the prompt gets long.
Why position matters
A system prompt sits at the very start. Then come chat history, documents, tool results and finally the new user message. In a long request, your key rule can be thousands of tokens away from the text the model is answering.
Models generally handle short, focused prompts better than long, crowded ones. Many developers also find that instructions placed close to the question are followed more reliably than ones buried far above. This varies by model and task, so do not take it on faith. Test it with your own prompts.
There is also a safety reason. If your code ever trims context from the top, the system prompt is the first thing at risk. A copy of the key rule near the end survives that.
How to do it
Keep the full system prompt where it is. Then add a short reminder right before or after the user's message:
[system] You are a support assistant. ... (full rules)
[history ...]
[user] Where is my order #4471?
[system] Reminder: reply in JSON with keys "answer" and "next_step". Do not include card numbers.
Some APIs only allow one system message, or only at the start. In that case, append the reminder to the end of the latest user message, clearly marked, from your code.
Rules for the reminder:
- One or two lines. If you repeat all twenty rules, you are just doubling the prompt.
- Only the rules that break things. Format, safety, and the one goal of the task.
- Same wording every time. Stable text is easier to test, and a stable prompt prefix keeps prompt caching working. Put the reminder after the cached part, not inside it.
Test it
Build a long prompt with the rule only at the top, and another with the reminder at the end. Run both many times and count how often the rule holds. Test with a deliberately long input has a small test script.
Checklist
- Pick the one or two rules that must never break.
- Repeat them in a short line near the end.
- Keep the wording fixed.
- Check that trimming never removes them.
- Measure before and after.
Related: Long-chat drift.