Lesson 60.4 · 4 of 4 · 4 min read · Reviewed 24 Nov 2026
Preserving critical information
By the end, you can
- Protect critical facts from being lost in summaries.
- Use a pinned facts block.
Summaries are lossy. For most text that’s fine. For some facts it isn’t.
The case-facts block
Keep a small, structured block that your code maintains and places in every request:
<case_facts>
customer_id: C-20931
order_id: ORD-48213
issue: parcel damaged on arrival
agreed: refund 64.50 USD to original card, approved by agent
promised: confirmation email within 1 hour
constraints: customer asked not to be phoned
</case_facts>
- It’s not summarised; it’s copied forward as is.
- The agentAgent: A system where a model decides its own next steps, calling tools in a loop until the task is done. updates it through a tool, such as
update_case_facts, so changes are deliberate and logged. - It sits near the latest turn, where attentionAttention: The mechanism that lets each token weigh every other token in the context when building its representation. is strongest (59.3).
Check summaries
After compactionCompaction: Summarising older conversation history so a long session fits in the context window while keeping what matters., a quick code check can confirm that ids and amounts in the summary match the facts block. Mismatches point at a bad summary.
Key points
- Some facts must never be paraphrased or dropped: ids, amounts, deadlines, constraints, promises.
- Keep them in a structured 'case facts' block that is copied forward unchanged.
- Check that summaries didn't contradict the pinned facts.
Pin case facts and catch summary drift
Keep critical values in a pinned case-facts block that is copied forward unchanged, and write a check that catches a summary which contradicts it.
You will have: A CaseFacts class with a logged update tool, and a drift check that flags a bad summary.
Steps
- Write CaseFacts with an update(key, value, reason) method that logs every change.
- Render the facts as a <case_facts> block placed just before the newest turn.
- Write check_summary(summary, facts) that finds every id and amount in the summary and compares it with the pinned values.
- Run it on a good summary and on a drifted one that says 46.50 instead of 64.50.
- Print the change log and both check results.
Done when
- The good summary passes with no mismatches.
- The drifted summary is flagged: mismatch refund 46.50 vs 64.50.
- Every fact change appears in the log with a reason.
Open in the Playground No API key needed.
Starter code (Python)
import re
class CaseFacts:
def __init__(self, **facts):
self.facts, self.log = dict(facts), []
def update(self, key, value, reason):
# TODO: record (key, old, new, reason) in self.log, then set the value
self.facts[key] = value
def render(self):
return "<case_facts>\n" + "\n".join("%s: %s" % kv for kv in self.facts.items()) + "\n</case_facts>"
def check_summary(summary, facts):
# TODO: for each amount (like 64.50) and order id (like ORD-48213) in the summary,
# report a mismatch if it is not one of the pinned values
return []
cf = CaseFacts(order_id="ORD-48213", refund="64.50", contact="email only")
cf.update("refund", "64.50", "approved by agent")
print(cf.render())
print("good:", check_summary("Refund of 64.50 agreed for ORD-48213.", cf.facts))
print("drifted:", check_summary("Refund of 46.50 agreed for ORD-48213.", cf.facts))
Show a solution
import re
class CaseFacts:
def __init__(self, **facts):
self.facts, self.log = dict(facts), []
def update(self, key, value, reason):
self.log.append((key, self.facts.get(key), value, reason))
self.facts[key] = value
def render(self):
return "<case_facts>\n" + "\n".join("%s: %s" % kv for kv in self.facts.items()) + "\n</case_facts>"
def check_summary(summary, facts):
problems = []
for amount in re.findall(r"\d+\.\d{2}", summary):
if amount != facts["refund"]:
problems.append("mismatch: refund " + amount + " vs " + facts["refund"])
for oid in re.findall(r"ORD-\d+", summary):
if oid != facts["order_id"]:
problems.append("mismatch: order " + oid + " vs " + facts["order_id"])
return problems
cf = CaseFacts(order_id="ORD-48213", refund="0.00", contact="email only")
cf.update("refund", "64.50", "approved by agent")
print(cf.render())
print("log:", cf.log)
print("good:", check_summary("Refund of 64.50 agreed for ORD-48213.", cf.facts) or "no mismatches")
print("drifted:", check_summary("Refund of 46.50 agreed for ORD-48213.", cf.facts))
Finished the chapter? Take the chapter check.