Gemini File Slicing: Load Just One PDF Page or Spreadsheet Cell Range
Gemini's file slicing lets agents pull one page or cell range from huge PDFs and spreadsheets instead of loading the whole file into context.

What is Gemini file slicing?
File slicing is a Gemini API feature that lets a model request a specific piece of a large file, a single PDF page or a named tab and cell range in a spreadsheet, instead of pulling the entire document into its context window. Rather than uploading a 200-page annual report and letting the model scan all of it, the agent identifies which page holds the answer and loads only that page. The rest of the file stays out of context entirely.
This matters because context windows are not free. Every page of a PDF or every row of a spreadsheet that gets loaded costs tokens, and tokens cost money and latency. A model that only needs one number from a chart on page 47 shouldn’t have to pay for pages 1 through 46 and 48 through 200.
TL;DR
- File slicing lets Gemini load a single PDF page or a defined spreadsheet range instead of ingesting the whole file into context.
- In a demonstrated example, pulling one page from a long annual report used a few thousand tokens versus more than 200,000 tokens for the full PDF.
- The same approach works on spreadsheets: an agent can load one tab and a specific cell range rather than the entire workbook.
- Text-only slices can’t see charts or images, so if the answer lives inside a visual element, the agent has to load that page as an image instead of as extracted text.
- File slicing follows the same logic as tool retrieval and code mode covered elsewhere in Gemini’s recent API updates: load only what you need, when you need it.
- The feature is part of a broader pattern of context discipline showing up across agent tooling, where unnecessary data in the context window is treated as a cost to be minimized, not a convenience.
Stop stitchingscripts.Ship one system.
One spec produces the whole app, with security and compliance included.
Why does loading entire files into context become a problem?
Large language models process everything in their context window on every turn. If an agent has a 300-page PDF attached and needs one fact from it, the naive approach is to dump the whole document into context and let the model search it. That works, but it’s expensive and it scales badly.
The cost shows up in a few ways. First, raw token volume: a long PDF or a wide spreadsheet can easily run into hundreds of thousands of tokens once converted to text or images. Second, retrieval accuracy: models searching through huge amounts of irrelevant content are more likely to miss the right detail or get confused by similar-looking data elsewhere in the document. Third, latency and cost compound with every follow-up turn, since most implementations resend context on each request.
This is the same underlying problem that drives interest in tool retrieval and code execution patterns for agents with large tool libraries: context is a scarce resource, and anything that doesn’t need to be there is actively working against the model.
How does file slicing actually work?
Instead of treating a PDF or spreadsheet as one blob of content to upload wholesale, file slicing gives the model (or the calling application) a way to specify a target: a page number in a PDF, or a tab name and cell range in a spreadsheet. The API then loads just that slice into context.
In a demonstrated case, an agent was given a long, made-up annual report with a specific number buried inside a chart on one page. Instead of loading the full document, the agent first read the table of contents, used that to locate the right section, then loaded only that page. The full PDF would have run past 200,000 tokens; the single-page slice used a few thousand. The savings come from the same place code mode and tool retrieval get theirs: the model only pays for what it actually consumes, not for everything that exists.
For spreadsheets, the mechanism is conceptually the same but shaped differently. Instead of a page number, you specify a tab and a cell range. An agent that needs Q3 revenue figures from a specific sheet doesn’t need to load every tab and every row of a workbook that might contain years of financial history.
What are the limits of file slicing?
The biggest limitation is that a text-only slice cannot see charts, images, or other visual elements embedded in a page. If the number an agent needs is printed as text, a text slice works fine. If that number only exists inside a bar chart or a scanned image, the agent needs to load that page as an image rather than as extracted text. This means agents working with visually dense documents, financial reports with embedded charts, scanned forms, slide decks exported as PDF, need logic that recognizes when a slice should be requested as an image rather than text.
Build a claims
triage app for
4,000 insurance
adjusters
One prompt. Role-based access, audit trail and SSO come built in.
This also means file slicing isn’t a one-shot operation in many real workflows. An agent often has to make an initial pass (reading a table of contents, a summary sheet, or a tab list) to figure out which slice to request before it can retrieve the right piece. That’s a reasonable tradeoff: a small navigational step costs far less than loading the entire file speculatively.
How does file slicing compare to tool retrieval and code mode?
File slicing addresses a different part of the same underlying problem that tool retrieval and code mode solve for agent tooling. Tool retrieval keeps unused tool definitions out of the model’s context until they’re actually needed. Code mode keeps bulk intermediate data, like API results, out of context by running loops and filtering logic in a sandboxed program rather than pulling every record through the model. File slicing applies the identical principle to static files: don’t load content the model isn’t going to use.
All three mechanisms share a philosophy: context is a budget, and the job of good agent design is to spend it only on what the model actually needs to produce the final answer. Where tool retrieval and code mode target tool-calling agents (the kind that query APIs, databases, or external services), file slicing targets agents working directly with documents and spreadsheets attached as inputs. An agent could plausibly use both at once, for example calling a tool that itself returns a sliced portion of a large file, keeping both the tool definitions and the file content pared down to what matters.
Is file slicing worth using for every file-based task?
Not for every case. If a file is small, loading it in full is simpler and the token savings from slicing won’t matter much. The value shows up specifically with large documents, long reports, big workbooks, multi-hundred-page PDFs, where the cost of loading everything is substantial and the actual information needed is concentrated in one or two spots.
It’s also worth weighing against accuracy. A model that has to guess which page or range to request based on incomplete information (like a table of contents) can occasionally pick the wrong slice and need a second pass to correct course. That’s usually still cheaper than loading the whole file, but it’s not guaranteed to be a single clean lookup every time, especially with documents that have unclear structure or inconsistent formatting.
For spreadsheets specifically, slicing works best when the data has a predictable shape, like a known tab name and a stable set of columns. Highly irregular spreadsheets with scattered relevant data across many tabs may need more exploration before the agent can confidently request the right range.
Frequently Asked Questions
What file types support slicing?
Based on available demonstrations, PDFs and spreadsheets are the two file types covered. PDFs can be sliced by page, and spreadsheets can be sliced by tab and cell range.
Can file slicing read charts and images inside a PDF?
Not as a text slice. A text-only slice extracts text content from a page and cannot interpret visual elements like charts. If the needed information is inside a chart or image, the agent needs to request that page be loaded as an image instead.
Does file slicing require the model to know the file’s structure in advance?
Everyone else built a construction worker.
We built the contractor.
One file at a time.
UI, API, database, deploy.
Generally yes, at least approximately. In practice an agent often reads something like a table of contents or a sheet list first to figure out which page or range to request, then retrieves just that slice.
How much does file slicing actually save in tokens?
Savings scale with file size and how concentrated the needed information is. In one demonstrated example, a single relevant page used a few thousand tokens compared to more than 200,000 tokens for the full document, but actual savings will vary by file and task.
Is file slicing related to tool retrieval or code mode?
They solve related problems but apply to different things. Tool retrieval and code mode manage context spent on tool definitions and tool-call results. File slicing manages context spent on static file content like PDFs and spreadsheets. All three aim to keep irrelevant content out of the model’s context window.
