Budgeting web data
Truncating a web page for an LLM without cutting the answer
Set a character cap per page type from where answers actually sit in your pages, check that it holds, and tell the model when a page was cut.
By Curtis Mccann, Live Web Data team · Published
This article was drafted with AI assistance from the sources listed below and edited and published by the Live Web Data team. Disclosure: the Live Web Data API, which this article mentions, is this site's own product.
- 1Collect pairsReal questions, each with the page that answers it.
- 2Fetch as you sendSame format and same main-content setting as production.
- 3Find the answer offsetThe character where the answer text ends.
- 4Cap with a marginLatest offset plus a labelled margin, for example 25%.
- 5Flag the cutTell the model when a page was truncated.
A character cap is the cheapest control on the token bill. It is also the one that breaks answers without a sound. A cap keeps the start of the page and drops the rest, and nothing in the model's reply says the part it needed was in the dropped text. The web data budget guide sets a cap per page type. This post is about checking that the answer survives it.
What a cap actually cuts
The decision is how many characters of each page to keep. A simple cap keeps the head of the page, up to a fixed limit. Change it when your measurements show answers ending past that limit.
Two things decide what the limit costs you. The first is the format. A full-page conversion puts the header, the menu and the cookie text before the article, so they spend part of the limit first. A main-content conversion moves the article to the start, and the same limit reaches further into it. The second is the page type, covered below.
Tools pick very different defaults. The reference fetch server in the Model Context Protocol servers repository returns at most 5,000 characters by default (max_length), starting at character 0 (start_index). Its README says the response is truncated and that a model can pass start_index to read the page in chunks until it finds what it needs. That moves the decision to the model, one call per chunk. In your own app you can make it once, in code, from measurements.
Where the answer sits depends on the page
Before you measure, expect the offsets to differ by page type. These are patterns to check on your own pages, not rules:
- Pricing and status pages. The plan table or the current status is often near the top. A small cap tends to hold.
- Reference docs. The parameter a user asks about can sit in the middle of a long table. A cap that fits the first section cuts the rest.
- Changelogs. The newest entry is usually first. A question about an older version is the one that falls past the cut.
- Long articles. The conclusion is at the end. A cap that fits a summary of the opening misses it.
So one cap for every page is the wrong shape. Measure per page type.
Measure the answer offset
The answer offset is the character in the fetched text where the answer to a question ends. It turns "is the cap big enough?" into a number per page.
- Collect 20 or more real questions from your logs, each with the page that answers it.
- Fetch each page in the exact format and main-content setting you use in production, and save it.
- For each pair, pick a short phrase from the answer and find where it ends in the saved text.
- Take the latest offset per page type and add a margin. The margin is an assumption; label it.
from pathlib import Path
# One entry per real question: the saved page and a phrase from its answer.
pairs = [
{"file": "pages/pricing.md", "answer": "per seat"},
{"file": "pages/limits.md", "answer": "requests per minute"},
]
offsets = []
for pair in pairs:
text = Path(pair["file"]).read_text(encoding="utf-8")
start = text.find(pair["answer"])
if start == -1:
print(pair["file"], "answer not found: check the phrase or the format")
continue
end = start + len(pair["answer"])
offsets.append(end)
print(pair["file"], "answer ends at character", end, "of", len(text))
if offsets:
cap = int(max(offsets) * 1.25) # assumption: a 25% margin
print("starting cap:", cap, "characters")
A worked example with that labelled margin: if the latest answer in your docs pages ends at character 6,400, the starting cap is 6,400 × 1.25, or 8,000 characters. Run the script again when the site changes its layout, because a new banner or menu shifts every offset.
A phrase the script cannot find is a finding too. Either the phrase is wrong, or the format you send drops the text the answer was in.
Why not send the whole page
Sending everything avoids the cut, but a longer input is not free on quality either.
In "Lost in the Middle" (Liu et al., TACL 2023), models were tested on multi-document question answering and key-value retrieval. Performance was often highest when the relevant information was at the beginning or the end of the input, and it dropped significantly when the models had to use information in the middle of a long context. That held for models built for long contexts too.
Chroma's "Context Rot" report from July 14, 2025, tested 18 models. It found that performance becomes less reliable as input length grows, even on simple tasks. It also found that a single distractor, related text that does not answer the question, lowers performance compared with the baseline, and that the effect grows with input length.
A page's menus, related-article lists and footers are the kind of text that adds length without adding the answer. A cap fitted to the answer offset removes some of it, as long as the answer itself stays in.
When the answer is past any reasonable cap
If an answer sits far down a long page, raising the cap for every page to fit it would raise the token bill on all the others. Options, in order:
- Read a more specific URL. If the site splits a long reference into one page per topic, fetch that page instead.
- Switch to main content. If the offset falls a lot, the menus were the problem.
- Raise the cap for that page type only. Keep the small cap everywhere else.
- Flag the cut. Store whether each copy was truncated, and say so in the context, for example "This page was cut at 8,000 characters." The model can then say the answer is not in the part it has, instead of saying it does not exist.
The token cost post shows how to turn a token ceiling into characters, so the cap you measure here and the budget you plan there use the same unit.
How this maps to Live Web Data API
text.maxCharacters caps the content of each page, and verbosity compact returns the main content, so the cap is spent on the article rather than the menus. Set both to the values you measured above. Failed fetches cost 0 credits. The API reference lists the options.
Frequently asked questions
How many characters of a web page should I send to an LLM?
There is no single number. Measure where the answers to real questions end in your own pages, in the format you send, and set the cap a margin above the latest one. Set it per page type, because a pricing page and a long reference page put the answer in very different places.
Is it better to send the whole page so nothing is lost?
Not always. Research on long inputs found that models use information in the middle of a long context less reliably than information at the start or end, and that related text which does not answer the question lowers accuracy. A cap that keeps the answer and drops the rest can cost less without hurting the answer.
How does the model know a page was truncated?
Only if you tell it. Store a flag with each copy that says whether it was cut, and add a short note to the context, so the model says the answer is not in the part it has instead of saying it does not exist.