GrepBoard/Manuals
605 manuals ·

Gemini long-document summary: check page citations by script

·Tested on Gemini 3.8 Flash · Python 3.13 · 2026-11·Test scope ↓·6 steps

Have Gemini cite a page on every line of a 30-page report summary, then check with Python that each line's numbers appear on that page. Eight runs per order.

A summary line ends with "(p. 12)", but page 12 has no such number. A page citation only works as evidence if something checks it, and opening every page by hand defeats the point. This post runs that check on a 30-page fictional report. A similar idea, quoting the source and verifying it with grep, is in Make Claude quote the source in a summary.

[1] Prepare the document. It is a fictional "Garam District Shared Bicycle Pilot: Results Report" and has nothing to do with a real organization. Text has no page boundaries, so each page starts with a === Page N === line. The body is 13 pages (the title page is page 1), followed by appendices: monthly rentals by station (7 pages), maintenance logs (6) and complaint cases (4). That makes 30 pages and about 11,000 characters. Page numbers and section numbers are deliberately offset: the end of page 5 says "Section 5 considers moving or closing these 11", and Section 5 is on page 6.

[2] Put the report first and the instruction last. Google's Prompt design strategies says to supply large context such as documents first and to place the specific instruction or question at the very end of the prompt. The page mark is fixed as (p. N) at the end of the line so a script can read it.

text
<report>{full report text with page marks}</report> Summarize the report above. Rules:- Cover both the body and the appendices. Use at most 12 lines, and start each line with `- `.- End each line with the page that holds the content as `(p. N)`. For several pages write `(p. N, M)`.- Use only numbers and wording that appear in the report. Do not write anything you cannot confirm on the cited page.- At least 3 lines must cover the appendices.- Do not add greetings or explanations.

[3] Save it as prompt.txt and run the same command 8 times. Only the output file name changes, out1.txt to out8.txt. Each run took 1 to 2 minutes.

console
$ agy -p "$(cat prompt.txt)" --model gemini-3.8-flash --effort medium --output-format text > out1.txt

Part of the 4th result:

output
- Total rentals over six months were 93,640, monthly rentals peaked at 19,870 in June, and there were 7,315 registered users of whom 4,960 (67.8%) were repeat users. (p. 3)…- In Appendix B maintenance summary, jobs received were 392 in Mar with average handling time of 45 minutes, and 362 in Aug with average handling time of 48 minutes. (p. 21, 26)- Appendix C complaint cases included C-01 cannot return (Yeoul School gate), handled in 228 minutes, and C-02 dock noise (Dasom Park), handled in 305 minutes. (p. 27)

[4] The checking script reads the text of each page, finds the pages each summary line cites, and applies three rules. A line fails if it has no page mark or cites a page that does not exist. It fails if any number in the line is missing from all the cited pages. A line without numbers passes only if its words overlap most with the cited page. The full script is about 60 lines; this is the number check.

check_pages.py (excerpt)
NUM = re.compile(r"\d[\d,]*(?:\.\d+)?")CITE = re.compile(r"\((?:쪽|pp?\.)\s*([\d,\s]+)\)") def nums(s):    return {n.strip(",") for n in NUM.findall(s)} …        cited = [int(x) for x in re.findall(r"\d+", m.group(1))]        if not cited or any(c not in pages for c in cited):            rows.append((False, f"page does not exist {cited}", l)); continue        cited_text = "\n".join(pages[c] for c in cited)        ns = nums(body)        if ns:            have = nums(cited_text)            miss = sorted(n for n in ns if n not in have)            if miss:                rows.append((False, f"numbers {miss} not on page {cited}", l)); continue            rows.append((True, "numbers match", l)); continue

Exit code 0 means every line passed and 1 means at least one failed. The end of the output for the 4th result (lines are cut at 90 characters):

console
$ python check_pages.py doc.txt out4.txt…OK   numbers match | - In Appendix B maintenance summary, jobs received were 392 in Mar with average handling tOK   numbers match | - Appendix C complaint cases included C-01 cannot return (Yeoul School gate), handled in 212 of 12 lines passed, 0 failed

[5] Count the results. The same prompt was also run with the instruction placed before the report, 8 runs each.

Instruction positionRunsRuns with outputRuns with every line passingLines
After the report (prompt above)888 of 893 of 93
Before the report877 of 780 of 80

One run of the second kind returned nothing: the agent tried a tool call that headless mode cannot approve. A rerun of the same prompt produced 11 lines, all passing; it is not in the table. Every run with output stayed within 12 lines and had at least 3 appendix lines (3 to 4 per run, 46 in all). With this document there was no visible difference in page accuracy between the two orders. Lines citing two or more pages numbered 10 of 93 in the first kind and 1 of 80 in the second. [6] Check that the script catches wrong summaries. Seven hand-made variants of the 4th result (page shifted by one, one number changed, a nonexistent page, page mark deleted, a number from another page, an appendix page shifted, appendix digits swapped) were all caught. These are not model outputs. One representative case shifts an Appendix A line from page 14 to page 15 (the script's output cuts the line at 140 characters):

output
FAIL numbers ['01', '02', '1,115', '1,293', '1,973', '2,374', '2,430', '2,440', '753'] not on page [15] | - Appendix A monthly rentals by st

[7] Two places can still go wrong. First, a line that cites several pages at once, such as (p. 27, 28, 29, 30) for a list of complaint cases, passes as long as the numbers appear on any one of those pages; the script cannot tell that the other pages are unrelated. No such line appeared in these English runs, but nothing in the script prevents it. The script reads only comma-separated pages, so a hyphenated range like (p. 27-30) would fail as "no page mark"; none of the English runs wrote one. Adding "one page per line; split a claim that spans two pages into two lines" to the rules would address it, but that change was not run. Second, matching numbers do not prove the interpretation is right. A line that reads "67.8%" as a different quantity still passes if the number is on the page.

Do not stop at the page numbers for a contract or a medical record, where one sentence can change the outcome. Open the cited page and read it.

#summarize#gemini#long-document