LLM Summarization Techniques: A Practical Guide
How to summarize with LLMs: extractive vs abstractive, prompts for length and audience, refine and tree summarization for long files, and faithfulness checks.
Summarizing text is one of the most common jobs given to large language models, and one of the easiest to get subtly wrong. A summary can read fluently and still drop the key point or add a detail that was never in the source. This guide covers the choices that matter in practice: which kind of summary you want, how to prompt for it, how to handle documents that are too long for one call, and how to check the result. Each technique links to the official documentation or the research paper it comes from.
Extractive vs abstractive summaries
There are two broad families of summary.
| Extractive | Abstractive | |
|---|---|---|
| What it produces | Sentences or passages taken from the source | New text that restates the source |
| Main risk | Choppy output, missed connections between points | Wording or facts that are not in the source |
| Easy to verify? | Yes, every line can be traced back | Needs a separate consistency check |
| Typical use | Legal or compliance excerpts, quote lists | Briefings, digests, executive summaries |
The pointer-generator paper by See et al. describes abstractive systems as ones “not restricted to simply selecting and rearranging passages” from the input. The same paper names two weaknesses of neural abstractive models: they can get factual details wrong and they tend to repeat themselves. Their fix was a hybrid model able to copy words straight from the source while still generating new ones (See et al., 2017).
With an LLM you can get either behaviour from a prompt. Asking for “the five sentences from the text that best capture its argument, quoted exactly” gives you an extractive summary that you can verify by string matching. Asking for “a three-paragraph brief” gives you an abstractive one, which needs more checking.
Prompting for a summary: length, audience, format
A vague request like “summarize this” leaves the model guessing at every decision that matters. Anthropic’s prompting best practices suggest being explicit about the output format and constraints, and explaining why a constraint exists so the model can generalize from it. For summaries, that means stating:
- Length, in a unit the model can count: sentences, bullets or a word ceiling.
- Audience: “for a support engineer who will act on it” produces a different summary from “for a CFO deciding on budget”.
- Format: bullets, a fixed set of headings, or JSON fields if another program reads the output.
- Scope: what to leave out (boilerplate, legal disclaimers, small talk in a transcript).
The same guide recommends wrapping each input document in its own XML tags with source metadata, and giving a few examples wrapped in example tags when you need a consistent style. A summary prompt built that way might look like this:
<documents>
<document index="1">
<source>incident_report_0412.txt</source>
<document_content>{{REPORT}}</document_content>
</document>
</documents>
Summarize the incident report for the on-call engineer who takes over next shift.
They need to act on it, so keep only what changes what they do.
Output: at most 5 bullets, then one line starting "Open question:".
Use only facts stated in the report. If something is unclear, say so instead of guessing.
Long documents: refine, tree summarization and map-reduce
When a document is longer than what fits in one prompt, you split it into chunks and combine partial results. LlamaIndex exposes the main strategies as “response modes” on its response synthesizer:
| Mode | How it works | Trade-off |
|---|---|---|
refine | Answers from the first chunk, then passes that answer plus the next chunk back to the LLM to improve it, chunk by chunk | One LLM call per chunk; the docs describe it as good for detailed answers |
compact (default) | Like refine, but packs as many chunks as fit into each call first | Fewer calls than refine |
tree_summarize | Summarizes packed groups of chunks, then treats those summaries as new chunks and repeats until one answer is left | The docs label it as good for summarization |
simple_summarize | Truncates everything to fit one prompt | Quick, but can lose detail |
accumulate | Runs the same query on each chunk separately and concatenates the results | Useful when each section needs its own summary |
The classic map-reduce pattern (summarize each chunk independently, then summarize the summaries) maps closely onto tree_summarize, which is the recursive, hierarchical form of it. refine is the sequential alternative: it keeps one running summary, which helps with documents where later sections depend on earlier ones, but it cannot run chunks in parallel.
A working example
This is adapted from the LlamaIndex response synthesizer docs. It runs TreeSummarize directly on a piece of text with a custom prompt that takes an extra variable at query time:
from llama_index.core import PromptTemplate
from llama_index.core.response_synthesizers import TreeSummarize
qa_prompt_tmpl = (
"Context information is below.\n"
"---------------------\n"
"{context_str}\n"
"---------------------\n"
"Given the context information and not prior knowledge, "
"answer the query.\n"
"Please also write the answer in the tone of {tone_name}.\n"
"Query: {query_str}\n"
"Answer: "
)
qa_prompt = PromptTemplate(qa_prompt_tmpl)
summarizer = TreeSummarize(verbose=True, summary_template=qa_prompt)
response = summarizer.get_response(
"who is Paul Graham?", [text], tone_name="a Shakespeare play"
)
Swap the tone variable for an audience (“a new hire”, “a board member”) and the query for your summary instructions, and you have an audience-aware tree summarizer. For whole collections, LlamaIndex also has a Document Summary Index that builds a summary for each document (its example uses tree_summarize and a sentence splitter with chunk_size=1024) and then uses those summaries to pick which documents to retrieve for a query. If you are evaluating frameworks, the LlamaIndex listing has more on the project.
Using a long context window instead
Many current models accept inputs large enough to hold a full report, so chunking is not always needed. Two pieces of guidance apply when you go that route.
First, prompt layout. Anthropic’s guide says to put long documents near the top of the prompt, above the query and instructions, and to ask the model to quote the relevant passages before doing the task, which helps it focus on what matters in a long input.
Second, position effects. The Lost in the Middle study tested models on multi-document question answering and key-value retrieval. Performance was often best when the relevant information sat at the start or end of the input and dropped when it was in the middle, including for models built for long contexts. For summaries, that is a reason to check whether material from the middle of a long document actually shows up in the output. Our guide to context window optimization covers ordering, compression and budgeting in more depth, and managing context in RAG pipelines covers the retrieval side.
Faithfulness and hallucination checks
Fluency is not accuracy. In a large human evaluation of neural abstractive summarizers, Maynez et al. found hallucinated content in summaries from every system they examined, although pretrained models produced more faithful output. They also found that textual entailment measures tracked faithfulness better than standard metrics such as ROUGE (Maynez et al., 2020).
Practical checks, from cheapest to most thorough:
- Constrain the prompt. Tell the model to use only the source and to flag uncertainty. This lowers the risk but does not remove it.
- Quote-then-summarize. Ask for supporting quotes first, then the summary. Quotes can be checked against the source with exact string matching.
- Entailment checking. Split the summary into sentences and test whether the source supports each one. FactCC trained a model to flag summary sentences that conflict with the source and to point to the supporting and inconsistent spans (Kryściński et al., 2019). SummaC showed that off-the-shelf natural language inference models become useful for this once documents are split into sentences and scores are aggregated across sentence pairs (Laban et al., 2021); its models and datasets are published on GitHub.
- Human review of a sample, especially for high-stakes summaries.
Evaluating summary quality
Reference-based metrics compare your summary with a human-written one. The Hugging Face evaluate library includes metric cards for both common choices.
ROUGE (metric card) comes from Lin (2004) and compares a generated summary with one or more references. The card lists rouge1 (unigrams), rouge2 (bigrams), rougeL (longest common subsequence) and rougeLsum, with scores from 0 to 1. It is case insensitive and has an optional Porter stemmer.
import evaluate
rouge = evaluate.load("rouge")
predictions = ["hello there", "general kenobi"]
references = ["hello there", "general kenobi"]
results = rouge.compute(predictions=predictions, references=references)
print(results)
# {'rouge1': 1.0, 'rouge2': 1.0, 'rougeL': 1.0, 'rougeLsum': 1.0}
BERTScore (metric card) compares tokens using contextual embeddings rather than exact matches, so paraphrases score better than they would under ROUGE. It returns precision, recall and F1 and needs either a lang code or a model_type. The card warns that the default English model, roberta-large, is a download of more than 1.4GB, and suggests distilbert-base-uncased as a smaller option. The BERTScore paper reports a better match with human judgments than earlier metrics on the machine translation and image captioning systems it tested.
Neither metric checks faithfulness: a summary can share many words with a reference and still state something false. Use them to track changes over time on a fixed test set, and pair them with the consistency checks above. For a wider view of scoring methods, see LLM evaluation metrics and benchmarks.
A sensible default pipeline
- Decide extractive or abstractive based on how much you need to verify.
- Write a prompt that fixes length, audience, format and scope.
- If the document fits the context window, send it whole with the instructions after it; if not, use tree summarization (or refine when order matters).
- Ask for supporting quotes and check them against the source.
- Run an entailment-style check on the summary sentences for important outputs.
- Track ROUGE or BERTScore on a small reference set whenever you change the prompt or model.
Written by AI Agents Directory
Editorial team
Facts in this guide are checked against official documentation and repositories, which are linked in the article.