Summarizing long documents with AI in n8n: the method that goes the distance
Published 30 July 2026 · 4 min read
An 80-page annual report, a tender document, a six-month email thread, the transcript of a two-hour meeting: the documents you most need summarized are precisely the ones that don't fit comfortably into one LLM call. The "just paste everything into the prompt" temptation runs into a well-documented limit: a study by Liu et al. published in 2024 in Transactions of the Association for Computational Linguistics ("Lost in the Middle: How Language Models Use Long Contexts", see on Google Scholar) shows that models use information at the beginning and end of their context markedly better than what sits in the middle — exactly where the core of a long report lives. The good news: a map-reduce n8n pipeline sidesteps the problem cleanly.
The map-reduce strategy in three stages
- Split the document into coherent blocks (by chapter, section, or page group).
- Summarize each block independently (map): every LLM call works on a short context where nothing is "in the middle".
- Synthesize the partial summaries into a final summary (reduce), in several passes if the document is very long.
The split has a second, less obvious advantage: every partial summary is traceable. When the final summary claims something, you can walk back to the source block — impossible with a single call over 80 pages.
Step 1: extract and split the text
Extraction depends on the format: the Extract From File node retrieves text from native PDFs, DOCX and TXT — the same mechanics as in our guide to extracting Excel and CSV files. For the split, a Code node is enough: cut on natural boundaries (headings, double line breaks) at around 2,000 to 4,000 tokens per block, with slight overlap. The principles from our guide to document chunking for RAG apply, with one difference: for summarization you want bigger, semantically complete blocks rather than small retrieval-optimized chunks.
// Split by section, grouping to ~3000 tokens (≈ 12000 characters)
const sections = $json.text.split(/\n(?=#{1,3} |\d+\. )/);
const blocks = [];
let current = "";
for (const s of sections) {
if ((current + s).length > 12000) { blocks.push(current); current = s; }
else current += "\n" + s;
}
if (current.trim()) blocks.push(current);
return blocks.map((text, i) => ({ json: { block: i + 1, text } }));
Step 2: summarize each block (map)
Each block goes into an LLM call — via n8n's Summarization Chain node, which natively implements the map-reduce and refine strategies, or via a Loop Over Items loop over a Basic LLM Chain if you want fine control over the prompt. The partial-summary prompt must enforce three things: keep figures, dates, amounts and proper nouns verbatim; note the source section; and explicitly flag when a block contains no substantial information rather than padding. On model choice, outcomes matter more than raw horsepower: a study by Zhang et al. published in 2024 in TACL ("Benchmarking Large Language Models for News Summarization", see on Google Scholar) shows that instruction tuning, far more than model size, drives summary quality — a recent budget model summarizes better than a big, poorly instructed one, and cuts your map-stage costs tenfold.
Step 3: the final synthesis (reduce)
An Aggregate node (see our Split Out and Aggregate guide) gathers the partial summaries, then a final LLM call produces the synthesis. This is where a more capable model earns its keep: prioritizing, spotting contradictions between sections, producing a usable structure. Lock the output down with a Structured Output Parser — executive summary, key points, figures, risks, action items — rather than free text: that's what makes the summary usable by the rest of the workflow (Slack message, Notion page, PDF report).
If the partial summaries themselves exceed the synthesis model's comfortable context, add an intermediate stage: summarize the summaries in groups of ten, then synthesize the meta-summaries. Two stages handle documents of several hundred pages.
Reliability: the three checks that matter
- Coverage check: verify in code that every block actually produced a summary (a silently failed call = an entire section missing from the synthesis). An Error Workflow and retries on the LLM nodes cover transient failures.
- Numbers check: a Code node verifies that the source document's critical amounts and dates appear in the final summary; if not, the item goes to human review.
- Cost check: at volume, the map stages dominate the bill. Track spend per execution with our method for monitoring AI call costs, and consider a semantic cache if the same documents come around again.
Summarize or query? Both.
A summary gives the overview; it doesn't replace the ability to ask precise questions about the document. The two pipelines share their first steps (extraction, chunking): extend yours by indexing the chunks into a vector store to get a full RAG setup with Supabase. That's exactly the architecture of the RAG Assistant Pack (€119): PDF ingestion, a chatbot with citations and a question-answering API, to which a map-reduce summarization stage bolts on naturally.
A well-built summarization pipeline turns the pile of documents nobody reads into ten-line briefs everyone reads — with the exact numbers, and a path back to the source of every claim.
FAQ
Frequently asked questions
Why not just send the whole document to a large-context model?
Because the window a model accepts and the window it actually uses well are two different things. Long-context research shows models favor the beginning and end of the input and degrade recall for information in the middle. For a 5-page memo, a single call works fine; for an 80-page report where every section matters, splitting into partial summaries then synthesizing produces a more complete, more verifiable result.
What chunk size should I use for summarization?
Larger than for RAG: the goal isn't retrieval precision but the coherence of each partial summary. Blocks of 2,000 to 4,000 tokens cut on the document's natural boundaries (chapters, sections, speakers) work well. A slight overlap (5-10%) avoids cutting an idea in half.
How do I keep the final summary from losing the important numbers?
By demanding it explicitly at every stage: the partial-summary prompt must require preserving figures, dates, amounts and proper nouns, and the synthesis prompt must forbid aggregating numbers from different sections without citing them separately. A simple post-check — verifying that the source document's key amounts appear in the summary — catches residual losses.
What about scanned documents or image-based PDFs?
You need an OCR step or a vision model before the summarization pipeline: the Extract From File node only retrieves a PDF's native text. For scans, go through an OCR API or a multimodal model that accepts page images, then feed the recognized text into the same chunk → summarize → synthesize chain.
Bundle FlowKit Complet
€269