System Prompt Bloat and Cross-Session Memory Governance in LLM Applications

    This article explains why system prompts in large language model applications keep growing into runtime specifications, and what that growth costs in context budget, rule conflicts, maintainability, and observability. It then covers layered memory injection with on-demand reading, a five-category memory model with a three-month stability test, permission controls for multi-device sharing, and practical governance practices for keeping prompts modular, testable, and traceable.

    1. The Core Problem: System Prompts Are Becoming Runtime Specifications

    In early LLM applications, system prompts usually served three purposes: setting a role, constraining the output format, and declaring basic safety boundaries. As applications grew more complex, system prompts took on much more, including tool-calling rules, task routing, memory reads and writes, privacy policies, conflict handling, output style, and fallback behavior for errors. As a result, the system prompt has grown from a short instruction into a large runtime specification, close to an internal product spec.

    This growth is not only a length problem. It reflects engineering complexity being packed into a single context. Each new edge case adds another rule, and each new business requirement adds another classifier or explanation. In the short term, this approach quickly patches behavior. In the long term, it creates four risks:

    1. Rising context cost: Longer prompts increase inference cost and latency, and they raise the risk of truncation.
    2. More rule conflicts: Old and new rules may override each other, and the model has difficulty determining which rule takes priority.
    3. Lower maintainability: Changing one rule can affect many scenarios, and regression testing becomes difficult.
    4. Weak observability: It is hard to tell which rule or which memory influenced a particular answer.

    Therefore, the discussion of system prompt bloat should not stop at length. It should return to context governance. The key questions are which information must be injected every turn, which should be read on demand, which should be managed through tools or external systems, and which should never enter the model context at all.

    2. Cross-Session Memory: From Full Injection to Layered Injection and On-Demand Reading

    The core goal of cross-session memory is to give the model the context it needs in future sessions without injecting the full user history into the system prompt. A sound design uses layered injection:

    • Stable identity layer: A short profile injected every turn, such as long-term role, scope of work, and stable preferences.
    • Preference layer: Preferences for how answers are delivered, such as language, format, level of detail, and expressions to avoid.
    • Index layer: Only the path, summary, aliases, source, and update time of each memory file are injected. Full text is not.
    • On-demand reading layer: The model judges which files may be relevant to the question, then reads their full text through a controlled tool.

    The injection structure can be described as follows:

    1. injected_every_turn:
    2. profile: "profile.md body"
    3. preferences: "User preferences for response style"
    4. memory_listing:
    5. - path: "areas/project-a.md"
    6. summary: "Architecture decisions and to-dos for Project A"
    7. aliases: ["Project A", "A project"]
    8. source: "User conversation history"
    9. updated_at: "2025-01-01"

    When a user asks, “What architecture did we decide on for Project A earlier?”, the model should not answer “I don’t know” just because the full text was not injected. It should first check the index layer, identify areas/project-a.md as a likely match, and then call a general-purpose read tool to get the full text. The pseudocode is as follows:

    1. context = {
    2. "profile": read_file("profile.md"),
    3. "preferences": read_file("preferences.md"),
    4. "listing": load_manifest("manifest.yaml")
    5. }
    6. candidates = rank_memory_files(context["listing"], user_question)
    7. allowed_docs = []
    8. for item in candidates[:3]:
    9. if has_permission(user, item.path):
    10. allowed_docs.append(read_file(item.path))
    11. answer = generate_answer(
    12. system_rules=core_rules,
    13. context=context,
    14. retrieved_memories=allowed_docs,
    15. question=user_question
    16. )

    The key constraint is that before the model answers “this information does not exist,” it must check the index and try to read the files that may be relevant. However, reads must be limited by permission, relevance, and quantity. Otherwise, on-demand reading turns back into full loading.

    3. Memory Classification and Lifecycle: Using “Three-Month Stability” as the Test

    Memory files should not be stacked in a single flat folder. They should be classified by purpose. A practical approach uses five categories:

    1. Identity profile: Stable identity information, such as name, job title, role, and long-term areas of responsibility. The test is whether this information will most likely still hold three months from now.
    2. Preference configuration: Answer language, format, level of detail, common terminology, and expressions to avoid.
    3. Domain or project context: Project goals, architecture decisions, key constraints, to-do items, and milestones.
    4. People and relationship information: Collaboration roles, contacts’ responsibilities, and communication preferences. This data must be strictly anonymized and kept to the minimum necessary.
    5. Topic knowledge and event records: Long-term conclusions on a topic, historical decisions, and retrospective lessons learned.

    Each category needs lifecycle management that covers when to write, when to read, when to update, and when to archive or delete. A write should happen because future sessions will need the information, not merely because the user asked for it. Reads should not happen in full on every turn. They should be driven by the index and by the relevance of the question. Each update should keep its source and timestamp. Deletion should be under user control and auditable.

    4. Privacy Boundaries, Permissions, and Risks of Multi-Device Sharing

    Once memory is stored as files, permissions become a core design question. Which files can each session see? Do multiple entry points share the same files? Can different entry points modify the same file at the same time? How is sensitive information anonymized? How can users view, export, and delete their memory?

    At a minimum, the following principles should be applied:

    • Minimal writes: Save only stable information that will be valuable later, and avoid saving one-off context.
    • Scoped access: Divide visibility by user, session, and application entry point, and check permissions before every read.
    • Sensitivity levels: Label files by sensitivity. Highly sensitive content should not be injected or read by default, or it should require explicit authorization.
    • Source labeling: Record the source, update time, and confidence of each memory entry so the model does not treat guesses as facts.
    • User control: Provide ways to view, correct, delete, and turn off memory.
    • Audit trails: Log read and write events to help investigate unauthorized access and the spread of incorrect memories.

    When multiple devices share the same set of memory files, conflict risk is especially high. Two entry points may modify the same file at once, so the later write overwrites the earlier one. Engineering controls include version numbers, optimistic locking, idempotent writes, and conflict markers:

    1. file: areas/project-a.md
    2. version: 12
    3. updated_at: "2025-01-01T10:00:00Z"
    4. updated_by: "session-xxx"
    5. conflict_policy: "merge_or_mark"

    If a version conflict is detected, the system should not overwrite silently. It should merge the fields that can be merged, or mark the conflict and ask the user to confirm.

    5. System Prompt Governance: Modularity, Evaluation, and Observability

    Controlling prompt bloat requires more than cutting text. Teams need a governance mechanism:

    1. Modular split: Separate core safety rules, tool protocols, memory policies, and output formats into independent modules, and combine them by scenario.
    2. Explicit priority: Define the priority among safety rules, user instructions, memory content, and style preferences to reduce conflicts.
    3. Routing on demand: Use a lightweight classifier or rule-based router to decide which modules to load, instead of injecting everything on every turn.
    4. Compression and summaries: Generate summary indexes for long memories, and read the full text only when needed.
    5. Regression testing: Build a test set for key behaviors, covering memory reads, answers when no information exists, conflict handling, and privacy refusals.
    6. Observability: Record which modules were injected, which files were read, and which rules were triggered, so problems can be traced.
    7. Quotas and fallbacks: Limit the number of files and characters read per turn. When a limit is exceeded, fall back to summaries or ask the user for clarification.

    6. Practical Checklist

    • Keep the “inject every turn” set to a minimum: core safety rules, an identity summary, a preference summary, and the index.
    • The index should include the path, summary, aliases, source, update time, and sensitivity level of each file.
    • For answers of the “I don’t know” type, add a pre-check: search the index first, then read relevant files, and only then fall back to a default answer.
    • Use the “three-month stability” test to filter long-term memories and reduce noise.
    • For concurrent multi-device use, design version numbers and a conflict policy, and prohibit silent overwrites.
    • Enforce privacy boundaries in the tool permission layer, not only in the prompt text.
    • Put prompt modules under version control and regression evaluation to prevent unmanaged rule growth.

    System prompt bloat happens when context governance does not keep pace with feature growth. A cross-session memory file system offers one workable direction: replace “load everything” with layered injection, index-based navigation, on-demand reading, permission constraints, and conflict governance. Only when modularity, observability, and evaluation are built into the engineering process will system prompts stop expanding into an encyclopedia that is hard to maintain.