Cookbook

Field extraction

A stock count runs 70 rows to a page, and its two pages are scans with no text to copy. Send each page to TypeLLM as an image and read back every row as typed data: a SKU, an item and a count.

An array of objects returns up to 200 new items per call, so one call reads a whole page.

Updated October 17, 2026. Arrays of objects now return up to 4× more items per call, so a dense page of rows comes back in one call. Long-table extraction is also more complete and faster: up to 34% higher recall, and up to 27% faster. Before, this recipe read 50 rows and then asked for the row after the last one until the page was done.

The top of page 1 of the scanned stock count: a dense table of SKUs, items and counts.

Set up

Install the library, and PyMuPDF to turn the PDF pages into images:

pip install "typellm>=0.6.9" pymupdf

Get an API key from your dashboard:

import pymupdf
from typellm import TypeLLMClient

client = TypeLLMClient(api_key="YOUR_API_KEY", timeout=90)
doc = pymupdf.open("stock_count.pdf")

The scan is in the notebook's folder. Its pages hold no text layer: doc[0].get_text() returns ''.

Describe a row

ROWS is an array of rows, each a SKU, an item and a count:

CONTEXT = "One scanned page of a stock count."
ROW = {"sku": {"type": "string"}, "item": {"type": "string"}, "count": {"type": "integer"}}
ROWS = {"type": "array", "items": {"type": "object", "properties": ROW},
        "instructions": "Every row of the stock count on this page, in order."}

Read each page

Send each page as an image and read back its rows:

rows = []
for number, page in enumerate(doc, 1):
    image = page.get_pixmap(dpi=200).tobytes("png")
    page_rows = client.generate(context=CONTEXT, images=[image], questions={"rows": ROWS}).result["rows"]
    print(f"page {number}: {len(page_rows)} rows")
    rows += page_rows
page 1: 70 rows
page 2: 70 rows

Final result

print(f"{len(rows)} rows, {sum(row['count'] for row in rows):,} units")
140 rows, 16,351 units

It matches the footer printed on the last page: 140 lines, 16,351 units. The notebook runs all of it with your key, and downloads the scan for you: open it in Colab.

← all recipes