Gemini PDF tables: check page numbers and fields against the source
Send a small synthetic PDF to the current Interactions interface, then inspect labels, quantities and missing prices row by row.
Prepare a directly checkable one-page table · Send PDF data through the current interface · Keep current and earlier API fields separate
At a glance
Gemini document understanding handles PDF text and page visuals, including tables and diagrams. This task uses a one-page synthetic item table, sends inline PDF data and compares labels, quantities and pages with the original file. It delivers a request script and field-check record; model output still needs acceptance. The source is today’s actual official Document understanding page and its Python Interactions example. No SDK, upload or model was run.
PDF-to-field acceptance
Inspect a synthetic PDF
Open your one-page file and record labels, quantities and missing prices.
Inline document request
Read bytes, encode base64 and provide document and text inputs.
Compare source fields
Check page, row alignment, numbers and missing values before accepting data.
Prepare a directly checkable one-page table
Create a PDF without real data. Use columns Item, Quantity and Price, with Notebook quantity 3 and Pen quantity 2; leave both prices blank. Export it as demo.pdf with an existing editor and inspect the page, table and text. The SDK, credentials and model must already be available in your environment. This task claims no successful login or installation. The current official example uses gemini-4-hydrogen, so the script retains that name; check actual access and SDK compatibility before running.
| Page | Item | Quantity | Price |
|---|---|---|---|
| 1 | Notebook | 3 | Missing |
| 1 | Pen | 2 | Missing |
Send PDF data through the current interface
The source supports inline data for small documents or temporary processing, recommending Files API for larger or repeatedly referenced files. This task uses one small page without creating a Files API upload object. The documented PDF limit is 50MB or 1000 pages, with context constraints still applicable. Five MiB in the script is a smaller teaching cap, not the official limit. Base64 expands the payload, and a signature check does not validate a whole PDF.
import base64
from pathlib import Path
from google import genai
pdf_path = Path("demo.pdf")
pdf_bytes = pdf_path.read_bytes()
if not pdf_bytes.startswith(b"%PDF-"):
raise ValueError("Expected a PDF signature; inspect the document too")
if len(pdf_bytes) > 5 * 1024 * 1024:
raise ValueError("This demonstration accepts at most 5 MiB")
client = genai.Client()
interaction = client.interactions.create(
model="gemini-4-hydrogen",
input=[
{
"type": "document",
"data": base64.b64encode(pdf_bytes).decode("utf-8"),
"mime_type": "application/pdf",
},
{
"type": "text",
"text": (
"Read the item table. For each row give the page number, "
"the exact item label, and quantity. Mark missing prices "
"as missing. Do not infer prices or totals."
),
},
],
)
text = interaction.output_text
if not isinstance(text, str) or not text.strip():
raise RuntimeError("No usable text result; inspect the actual response")
print(text)
Keep current and earlier API fields separate
The old ai.google.dev document-processing address officially redirected to aistudio.google.com/docs/document-processing today. Its current Python example uses client.interactions.create, document data/mime_type and interaction.output_text. This script follows that interface rather than mixing earlier generate_content contents or file_data. The REST sample specifies Api-Revision 2026-05-20, but no unshown SDK parameter is added here. If interactions is missing in your SDK, resolve compatibility instead of silently switching APIs and claiming this task passed.
Compare each returned row
| Check | Requirement | If it fails |
|---|---|---|
| Page | Both rows come from page 1 | Inspect the original table location |
| Labels | Notebook and Pen remain distinct | Record mismatch; do not associate the wrong row |
| Quantities | 3 and 2 respectively | Check source cells rather than inferred values |
| Prices | Explicitly missing, without invented amounts | Reject invented fields |
| Text output | Nonempty readable text | Keep actual response cause and stop |
Requesting pages and fields aids manual checking; it does not guarantee accurate citations. A plausible total cannot prove numbers came from the right rows. Keep the original PDF unchanged and store input, response and check outcome separately. The table is a source baseline and acceptance expectation, not an observed model answer.
Stop at the failing layer
- A missing file, wrong signature or excessive teaching size stops before the request.
- SDK, authentication or model failure retains its real cause; examples do not prove account support.
- Empty or non-string output_text stops consumption; logs are not document output.
- Incorrect labels, quantities, prices or pages fail acceptance; retain discrepancies before deciding on a bounded retry.
- Multi-turn file reuse needs the separate Files API upload, processing and cleanup lifecycle, not an assumed permanent document store.
Verification and cost boundaries
The current official page was read for capabilities, inline examples, technical limits and multi-turn file guidance. The sample, prompt and checklist are original materials. No PDF export, script, authentication, API call or observed output occurred. Page understanding establishes no OCR or field-accuracy guarantee. Limits, tokens and prices need actual model/interface checks; no price or performance is promised.
Article sources
Original editorial content; official descriptions and checking suggestions are distinguished.