Sub topic 12
What summaries lose and how they go wrong
This chapter assumes you have read the earlier chapters on rolling summaries and the hybrid strategy. You should know how compact folds old messages into a summary and how build_request sends that summary with recent messages. A summary is a model's rewrite of your conversation, and it is lossy. Truncation fails visibly, because old messages are simply gone. A summary can fail silently, because it reads fluently even when it is wrong.
Why a summary is lossy by design
A summary is shorter than its source, so some information has to go. The summarizing model decides what to drop using general judgment. It does not know which detail your application needs. A casual remark may matter later. A long, vivid paragraph may be irrelevant.
You cannot remove this loss. You can control which kinds of loss you accept and catch the worst ones.
What gets lost
Summaries tend to lose the same kinds of detail.
| Lost detail | Example in the original | What the summary says | Later effect |
|---|---|---|---|
| Exact values | `/srv/app/config.yaml`, `$4,500`, `2026-12-01` | "a config file", "a modest budget", "soon" | The assistant guesses or asks again |
| Negations and constraints | "Do not touch the billing tables" | "Working on the database" | The assistant breaks a rule the user set |
| Reasons for decisions | "We rejected Redis because of licensing" | "Chose Postgres" | The assistant proposes Redis again |
| Uncertainty | "I think the bug is in the parser, but I'm not sure" | "The bug is in the parser" | A guess is treated as a finding |
| Order and timing | "First it worked, then it broke after the upgrade" | "It worked and it broke" | Cause and effect are lost |
| Attribution | "The assistant suggested X; the user rejected it" | "X was discussed" | Rejected ideas come back |
| Tone and preferences | "Keep answers short, no bullet lists" | Nothing | Style drifts back to the default |
Exact values, negations, and rejected options are the most expensive losses. They are small in token terms and they decide whether the assistant behaves correctly.
How summaries go wrong
Loss is the mild failure. The following failures are worse.
Invented facts
A model that rewrites text can add content that was never there. It may fill a gap with a plausible detail, merge two similar items, or state an assumption as fact. The prompt from the earlier chapter says "Do not add facts that are not in the conversation," which helps but does not guarantee anything. Once an invented fact is in the summary, later turns treat it as established history.
Drift across repeated summaries
A rolling summary is re-summarized every time compact runs. Each pass is a chance to drop or distort something, and the errors compound. A detail lost in pass 2 cannot be recovered in pass 5, because the original messages are gone from the prompt. The effect is like a game of telephone.
Because the diagram fence must name its type, here is the diagram in the required form:
Stale facts that never expire
If the user changes their mind, the summary may keep both versions or only the first. For example, the original message says "deadline is Friday" and a later one says "moved to Monday". A summarizer that only appends can leave both claims in the text. The assistant then chooses between them at random.
Summary text treated as instructions
The summary is sent as a system message in the build_request layout. Anything written into it carries system-level weight. If an old user message or a pasted web page contained instruction-like text, the summarizer may copy it, and it now appears with more authority than it had originally.
Growth beyond the budget
A summary that is allowed to grow will eventually crowd out the recent messages. The 300-word cap in the prompt is a request, not a limit. Models exceed word caps, so measure the summary with estimate_tokens and handle an oversized result in code.
Reducing the damage
No single technique fixes all of this. Use several together.
- Use a structured summary. Ask for named sections such as goals, decisions with reasons, constraints, exact values, and open tasks. A fixed layout makes omissions easier to notice and makes later updates replace items instead of piling up.
- Make updates explicit. Tell the model to replace a fact when the user changes it, and to remove completed tasks.
- Keep a separate list of pinned facts. Constraints and key values that must survive go in a pinned message, as in the earlier chapter on pinned content. They are not left to the summarizer.
- Check the output in code. Compare the summary against the source with simple rules, as shown below.
- Keep the full transcript outside the prompt. Store raw messages in a database. If a summary turns out to be wrong, you can regenerate it from the source instead of from an earlier summary.
- Limit the number of passes. Where you can, re-summarize from the stored transcript periodically instead of repeatedly summarizing summaries.
A guard that checks exact values
Exact values such as file paths, dates, and amounts are easy to find with a pattern. The guard below extracts them from the messages about to be folded in. It then checks that each one appears in the new summary, and it appends any that are missing.
import re
# Matches paths, numbers (including dates and amounts), and file names.
EXACT_VALUE = re.compile(
r"[\w.-]*/[\w./-]+|\$?\d[\d,.:-]*\d|\b\w+\.[a-z]{1,4}\b"
)
def extract_exact_values(messages):
values = set()
for message in messages:
values.update(EXACT_VALUE.findall(message["content"]))
return values
def missing_values(old_messages, summary):
return sorted(v for v in extract_exact_values(old_messages) if v not in summary)
def guard_summary(old_messages, summary):
missing = missing_values(old_messages, summary)
if not missing:
return summary
lines = "\n".join("- " + value for value in missing)
return summary + "\n\nExact values carried over verbatim:\n" + lines
old = [
{"role": "user", "content": "Deploy to /srv/app/config.yaml by 2026-12-01. Budget is $4,500."},
{"role": "assistant", "content": "Understood."},
]
summary = "The user wants a deployment finished soon with a modest budget."
print(guard_summary(old, summary))The output is:
The user wants a deployment finished soon with a modest budget.
Exact values carried over verbatim:
- $4,500
- /srv/app/config.yaml
- 2026-12-01You can call guard_summary(old, new_summary) inside compact right after summarize returns. The pattern is crude. It will carry over incidental numbers too, so the summary grows. Apply the token cap after the guard, and consider limiting the check to values from user messages. It also cannot catch lost negations or reasons. A regular expression cannot judge meaning, so those need the checks in the next chapter.
Choosing what to summarize
Some content is safer to keep than to summarize.
- Keep verbatim: constraints, API schemas, short code the user wrote, and anything the user said must be exact.
- Summarize: small talk, repeated clarifications, long explanations the assistant produced, and exploration that led nowhere.
- Discard with a note: very large pastes such as logs. Replace them with a one-line description and store the original elsewhere.
When a message is long and important, a better choice may be to trim around it, or to store it and retrieve it on demand. The last chapter of this tutorial covers that option.
Signs that a summary has failed
Watch for these symptoms in production.
- The assistant asks a question the user already answered.
- The assistant proposes an option the user already rejected.
- A name, number, or path in the answer differs slightly from the original.
- The assistant's behavior changes right after a compaction event.
- The summary token count rises on every pass.
Log each compaction with the old summary, the new summary, and the token counts. Without those logs you cannot tell whether a bad answer came from the model or from the summary.
Exercise
A user said early in a chat, "Never email customers directly; draft only." After two compactions, the assistant offers to send an email. Name two likely causes in the summarization pipeline and two fixes.
Show answer
Likely causes: the constraint was a negation that the summarizer dropped or rephrased as "working on customer emails", and repeated re-summarizing let the loss compound so the original wording was gone. Fixes: pin the constraint as its own system message so it never passes through the summarizer, and use a structured summary with a required "constraints" section. Keeping the raw transcript outside the prompt, so the summary can be regenerated from the source, is also a valid fix.
Exercise
Why does guard_summary not detect that a summary says "the bug is in the parser" when the user only said "I think the bug is in the parser"?
Show answer
It only checks that exact-looking tokens such as paths, numbers, and file names from the source appear in the summary. Hedged wording is a matter of meaning, and a pattern match cannot compare it. Catching it needs a test that asks a model, or a person, whether the summary preserves the uncertainty.