Lesson 3 - Loops Over Documents

Welcome to Loops Over Documents

So far your loops have produced short things — a newsletter, an email. This lesson scales up to loops that work over documents: a long report to summarize, a stack of customer feedback to theme, a policy to rewrite. Two challenges appear at this size. First, the input can be too big to handle well in one pass. Second — and more usefully — the document gives you a powerful new kind of check: you can verify that the output actually traces back to the source, catching the invented details that plague AI summaries.

By the end of this lesson, you will be able to:

  • Break a document too big for one pass into checkable passes
  • Use summarize-then-refine loops over long inputs
  • Turn the source document into a ground-truth check against invented claims
  • Recognize when to upload and reference rather than paste

Let’s start with the size problem.


When the Input Is Too Big for One Pass

Ask an AI to summarize a forty-page report in one go and something subtle happens: it skims. It attends to the start and end, gives the middle a light touch, and produces a summary that looks complete but quietly under-represents whole sections. This is the input-side twin of the drift problem from Lesson 1 — too much at once, and the model’s attention spreads thin.

The fix is to break the work into passes. Instead of “summarize this whole thing,” you loop over it in pieces: summarize section A, then B, then C, each as its own focused pass, then combine the pieces into the final result. Each pass is small enough for the AI to actually read closely, so nothing gets skimmed. This is just the loop applied to a big input — divide it into parts the model can handle well, and assemble.

A pipeline titled 'Break a big document into passes — and check the output against it'. On the left, a blue 'Long document, too big for one pass' with three sections A, B, C. Each section flows via an arrow to a purple 'Pass over A / B / C' box. The three passes combine into an orange 'Combine → draft, e.g. one summary'. That flows to a green 'Check vs source: does every claim trace back to the document?'. A dashed green arrow loops from the check back to the document, labelled 'the document is the ground truth — anything not in it is flagged'. A caption notes long inputs go in passes so nothing is skimmed, then the source itself becomes the check that catches invented claims.
Two moves for document loops. Break a big input into per-section passes so nothing gets skimmed, then use the source document itself as the check — every claim in the output must trace back to it.

A close cousin is summarize-then-refine: a first pass pulls out the raw material (key points, quotes, numbers), and a second pass shapes it into the final form. Splitting extraction from polishing keeps each pass focused, and it means your check can look at the extraction (“did it capture the right points?”) separately from the writing (“is it clear and on-length?”). It also makes errors easier to trace: if a fact is wrong, you can tell whether it was pulled wrong in the first pass or introduced during the rewrite in the second, and fix the right step instead of guessing.


The Document as a Ground-Truth Check

Here’s the part that connects straight back to Module 3. When you loop over a document, the document isn’t just the input — it’s the ground truth for your check. This is the strongest kind of check there is (Lesson 3.2), and a document loop hands it to you for free.

AI summaries and rewrites are notorious for slipping in details that aren’t in the source: a statistic that sounds right, a conclusion the document never drew, a quote nobody said. A vague check (“is this a good summary?”) sails right past these. But a source-anchored check catches them: “For each claim in the summary, quote the sentence in the source it comes from. Flag anything you can’t trace.” Now every invented detail has nowhere to hide — if it’s not in the document, there’s no sentence to quote, and it’s flagged. You’ve turned the document into an un-foolable check against hallucination.

Make every claim cite its source

The single most valuable move for any document loop is to require traceability: every fact in the output must point to where it came from in the source. It catches invented claims, and as a bonus it lets you spot-check in seconds — follow a couple of the citations back and confirm they say what the output claims. This is the “demand evidence” technique from Module 3, aimed at a document.


Upload and Reference, Don’t Paste

For anything long, upload the document to the chat (or attach it to your Project from Lesson 2) rather than pasting it into a message. Uploading keeps your conversation readable, lets the tool handle a much larger input than a single message comfortably holds, and gives the AI a stable thing to point back to when your check asks it to cite sources. Pasting a huge wall of text, by contrast, bloats the chat and makes the drift problem worse.

Once a document is attached, you can loop against it naturally: “summarize section 2,” “now check this summary against the attached report and flag anything not supported by it,” “revise to fix the two unsupported claims.” The document stays put as the reference while the loop runs around it. This is also where Projects shine — attach the stable reference documents once, and every chat in the Project can check against them.

Tool-specific note (durable idea underneath)

File size limits, supported formats, and how much of a long document a tool actually reads at once vary between ChatGPT and Claude and change over time — check each tool’s current help for specifics. The durable ideas don’t change: break big inputs into passes the model can read closely, and anchor the check to the source so invented claims are caught.


A Harborlight Example

The owner exports three months of customer feedback — a few hundred comments, far too much to eyeball — and wants the top five themes with a representative quote for each. A single “summarize this” would produce five plausible themes, some of which the feedback doesn’t actually support, plus quotes that may be paraphrased or invented.

Instead they run a document loop. First, passes: they have the AI group the comments into candidate themes in one pass, then, for each theme, pull the actual comments that belong to it in a second pass. Then the source-anchored check: “For each of the five themes, quote three real comments from the file that show it; if a theme has fewer than three real supporting comments, drop it.” That check does real work — two of the initial “themes” turn out to have only one genuine comment each and get cut, and every surviving quote is a real customer sentence, verifiable in the file. The result is five themes the owner can actually trust, because the check was anchored to the feedback itself, not to whether the summary sounded right.


Practice Exercises

Exercise 1: Break it into passes

You need to turn a 30-page supplier contract into a one-page plain-English summary. Describe a passes-based approach rather than one big prompt.

Hint

Pass 1: summarize each section (payment terms, delivery, liability, etc.) separately so none is skimmed. Pass 2: combine those section summaries into a one-pager. Then check the one-pager against the contract, requiring each claim to cite the clause it came from.

Exercise 2: Write the source-anchored check

Write a check for an AI summary of a news article that would catch invented details.

Hint

Something like: “For every factual claim in the summary, quote the exact sentence from the article that supports it. Mark any claim you cannot trace to a specific sentence as UNSUPPORTED.” Anything the article doesn’t actually say has no sentence to quote, so it gets flagged.

Exercise 3: Spot the risk

Someone pastes a huge report into one message and asks for a summary, then asks “is it accurate?” in the same chat. Name two problems.

Hint

One: pasting a huge input in one pass invites skimming, so the middle is under-covered. Two: “is it accurate?” is a vibe check by the same model in the same chat — it’ll likely say yes. Better: upload the report, summarize in passes, and check each claim against the source with required citations.


Summary

Loops over documents bring two challenges and one gift. The challenge of size is solved by passes: break a long input into sections the model can read closely, process each, and combine — optionally splitting extraction from polishing in a summarize-then-refine loop. The gift is the strongest check you can get: the document is ground truth, so a source-anchored check — “quote the sentence in the source that supports each claim; flag anything you can’t trace” — catches the invented details that a vague “is this good?” waves through. Upload and reference long documents rather than pasting them, which handles bigger inputs, keeps the chat clean, and gives the check something stable to cite against. Together these turn a big, error-prone “summarize this” into a loop that both covers the whole input and can prove its output came from the source.

Key Concepts

  • Passes — breaking a document too big for one pass into sections processed one at a time, then combined.
  • Summarize-then-refine — a first pass extracts raw material, a second shapes it, keeping each focused.
  • Source-anchored check — requiring every output claim to trace to a specific place in the source document.
  • Traceability — each fact citing where it came from; catches invented claims and speeds your spot-check.

Why This Matters

Document work is where AI is most useful and most dangerous at once: it can digest a stack of material in seconds, but it will also confidently invent details that were never there. The passes-and-source-anchored-check approach is what makes document loops trustworthy enough to rely on for real work — a summary you can defend because every line traces to the source. It’s the same discipline that lets a research report or a contract review hold up to scrutiny. Next, you’ll give loops even more reach, using built-in tools like web search so a loop can go and fetch what the document — or the model — doesn’t already contain.


Continue Building Your Skills

You can now loop over documents too big for one pass, and — more importantly — turn the source into a ground-truth check that catches invented claims. Make traceability a habit for any document work: if a claim can’t cite its source, it doesn’t ship. Next, you’ll let loops reach beyond what’s in front of them, using web search and other built-in tools to fetch missing information mid-loop.

Sponsor

Keep DATATWEETS free. Help fund practical data, AI, and engineering lessons for learners worldwide.

Buy Me a Coffee at ko-fi.com