📦 Moved to new directory. Last updated 12.2.2026. New location: claude-config/library/03-memory-state/deep-dives/state-09-system-prompt-pinning.html

Deep dive 9 of 27: System Prompt Pinning

Nov 19, 2026 · Michael Chang · Status in NurseOps Now: ✅ built

Show definitions in ( ) · hover a highlighted word for its meaning, click it for details · open with ?defs=1 to show definitions

Part of: Remembering the right things: state management in NurseOps Now, section Implementing Short-Term Memory: Token Budgets and Window Management (7.1) · All 27 solutions · ← Dynamic Context Loading · Textual Summarization →

Read in this order

  1. In plain words: what it is, without jargon
  2. The problem it solves: the problem, and the standard approach in my words
  3. How to implement it (ServiceApps): scenario, steps, code and real output
  4. In NurseOps Now: built or not, and where
  5. Trade-offs and Interview answer

In plain words

System prompt pinning (keeping the rules in a protected place that is sent on every call and never trimmed) keeps the AI's rules in a protected place that is sent on every call and never trimmed. Only the conversation history slides. However long the chat gets, the rules are always there.

In plain terms: the company handbook is bolted to the desk; only the pile of notes next to it gets cleared out.

The problem it solves

Sliding window truncation (silently dropping the oldest messages when the window is full) and Loss of instructional integrity (the AI losing its rules because they were pushed out of the window): if the rules are just the first message, trimming old messages throws the rules away first.

The standard approach (in my words): split the context into an immutable zone (rules) that is never truncated and a mutable zone (history) that slides.

How to implement it (ServiceApps)

Illustrative example: no ServiceApps (a company platform for IT tickets, HR requests and help-center articles) instance is connected, so the scenario and data are made up. The code is a self-contained sketch; it was run on that made-up data on Nov 19, 2026, and the output below is from that run.

The setting. ServiceApps (a company platform for IT tickets, HR requests and help-center articles) Assist, an AI helper inside a company's ServiceApps (a company platform for IT tickets, HR requests and help-center articles) portal. Employees ask it IT and HR questions; it answers from knowledge-base (KB (knowledge base: a library of help articles)) articles, looks up the employee's own tickets (incidents (a ServiceApps ticket for something broken) like INC0012345) and requests, and keeps one conversation per employee and ticket.

The scenario. ServiceApps (a company platform for IT tickets, HR requests and help-center articles) Assist's rule: never reset a password without identity verification. A chat reaches 10 turns and the window keeps only 6 messages.

Steps.

  1. Keep the rules as a separate field (the API's system field), not in the message list.
  2. Trim only the message list.
  3. Re-send the rules unchanged on every call.
  4. Test it: after a long chat, the rules must still be present.

The code (Python):

RULES = "You are ServiceApps Assist. Never reset a password without identity verification. Cite KB numbers."

def naive_window(history, limit=6):              # rules are just the first message, so trimming drops them
    msgs = [{"role": "system", "content": RULES}] + history
    return msgs[-limit:]

def pinned_window(history, limit=6):             # rules kept apart; only history is trimmed
    return {"system": RULES, "messages": history[-limit:]}

history = [{"role": "user" if i % 2 == 0 else "assistant", "content": f"turn {i}"} for i in range(10)]
n, p = naive_window(history), pinned_window(history)
print("naive : rules present?", any(m["role"] == "system" for m in n), "| first message:", n[0]["content"])
print("pinned: rules present?", bool(p["system"]), "| first message:", p["messages"][0]["content"])

Output (from running the code above):

naive : rules present? False | first message: turn 4
pinned: rules present? True | first message: turn 4

What to watch for.

In plain terms: the rulebook never leaves the desk, no matter how many notes pile up.

In NurseOps Now

Built. The rules (backend/app/prompts/assist_v1.md) go in the API's system field on every call, and only the history list is trimmed to 10 turns. See Step 2.

Trade-offs

Interview answer

"I never put the rules in the trimmable history. They go in the system field on every call, and only the conversation slides. That's the fix for the classic failure where a long chat pushes the policy (the health plan's written rules for when a test is covered) out and the agent (an AI that chooses which tools to use to answer) stops following it."

All data in this post is made up. No real people, tickets or patient data.

← Back to all 27 solutions in the state management blog

Key terms

Every highlighted word in this post links here. Click ↩ Back to return to the spot you came from.

agent
An AI that chooses which tools to use to answer.Used in: Interview answer↩ Back to where you were
incident
A ServiceApps ticket for something broken.Used in: How to implement it (ServiceApps)↩ Back to where you were
KB
Knowledge base: a library of help articles.Used in: How to implement it (ServiceApps)↩ Back to where you were
loss of instructional integrity
The AI losing its rules because they were pushed out of the window.Used in: The problem it solves↩ Back to where you were
policy
The health plan's written rules for when a test is covered.Used in: Interview answer↩ Back to where you were
prompt caching
The AI provider reusing an unchanged prompt start, so calls are cheaper and faster.Used in: How to implement it (ServiceApps)↩ Back to where you were
recursive goal injection
Repeating a short reminder of the rules before every AI answer.Used in: How to implement it (ServiceApps)↩ Back to where you were
ServiceApps
A company platform for IT tickets, HR requests and help-center articles.Used in: How to implement it (ServiceApps)↩ Back to where you were
sliding window truncation
Silently dropping the oldest messages when the window is full.Used in: The problem it solves↩ Back to where you were
system prompt pinning
Keeping the rules in a protected place that is sent on every call and never trimmed.Used in: In plain words↩ Back to where you were
tokens
Pieces of words the AI reads and writes; cost is per token.Used in: Trade-offs↩ Back to where you were