Tools,

Sparrow OCR on a Mac, tested

0 of 10

4B invoice numbers kept by Sparrow's cleanup

Get the text with one call

Install and run it

pip install "sparrow-parse[mlx]==1.6.3"
The Python call and the full query
QUERY = 'retrieve invoice_number, date, line_items, subtotal, tax, total. return response in JSON format, by strictly following this JSON schema: {"invoice_number": "str", "date": "str", "line_items": [{"sku": "str", "description": "str", "quantity": 0, "unit_price": 0.0, "amount": 0.0}], "subtotal": "float or null", "tax": "float or null", "total": "float or null"}.'
from sparrow_parse.extractors.vllm_extractor import VLLMExtractor
from sparrow_parse.vlmb.inference_factory import InferenceFactory

model = InferenceFactory({"method": "mlx",
    "model_name": "mlx-community/Qwen3-VL-4B-Instruct-4bit"}).get_inference_instance()
results, pages = VLLMExtractor().run_inference(
    model, [{"file_path": "invoice.jpg", "text_input": QUERY}])
print(results[0])

The 4B model read 324 of 324 numbers

10 invoice scans Numbers right Pages fully right
Qwen3-VL 2B, as Sparrow returns it 243 of 324 3 of 10
Qwen3-VL 4B, as Sparrow returns it 312 of 324 0 of 10
Qwen3-VL 4B, with the fix below 324 of 324 10 of 10

Numbers: qty, unit price and amount on 104 item rows, plus printed subtotals, taxes and totals. Fully right: every field matches, nothing added.

Sparrow cut the answer to one list

The 4B model answered every page with one plain JSON object, every field right. Then sparrow-parse 1.6.3 cleaned it.

The fix: parse the whole answer first.

import json
from sparrow_parse.vlmb.mlx_inference import MLXInference

_clean = MLXInference.process_response

def process_response(self, text):
    try:  # a whole JSON answer stays whole
        return json.dumps(json.loads(text.strip()), indent=2, ensure_ascii=False)
    except json.JSONDecodeError:
        return _clean(self, text)

MLXInference.process_response = process_response

Tested on the saved answers.

The 2B broke JSON and made up totals

Speed and memory on an M5 Max

6.5 sa page, 2B

8.6 sa page, 4B

7.5 GBpeak memory, 4B

Next to Tesseract and our Actor

Same 10 scans Numbers right Wrong ones flagged
Tesseract script 318 of 324 6 of 6
Our Actor, build 0.1.44 323 of 324 1 of 1
Qwen3-VL 4B, with the fix 324 of 324 No check

The script and the Actor flag numbers that do not add up or do not read as a row. Sparrow has no such check, and the 2B totals show why you want one.

The text step: one call to our Actor

PDF OCR to Markdown, our Apify Actor, reads a scan or photo by URL and returns Markdown, tables included.

The API call
curl -X POST "https://api.apify.com/v2/acts/brasspage~pdf-ocr-to-markdown/run-sync-get-dataset-items" \
  -H "Authorization: Bearer $APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"documentUrls": ["https://www.irs.gov/pub/irs-pdf/fw9.pdf"], "pages": "1-2"}'

What I tested, and what I did not

How I tested
  • 10 made-up invoice scans from the invoice OCR page test sets: 6 at 2550 x 3300 pixels, 4 at 1700 x 2200. Sparrow shrinks a page to fit 1250 x 1750, so all went in at about 1250 x 1617. 4 of them print subtotal, tax and total.
  • Python 3.12.12 on an Apple M5 Max with 128 GB, macOS 26.6. sparrow-parse 1.6.3, mlx 0.32.5, mlx-vlm 0.8.1, transformers 5.14.0.
  • Models: mlx-community Qwen3-VL-2B-Instruct-4bit and Qwen3-VL-4B-Instruct-4bit.
  • One run_inference call a page, one run at a time, at background priority (nice 19, taskpolicy -b). Seconds are rough.
  • Sparrow runs at temperature 0. A second 4B run gave the same Sparrow output on 10 of 10 pages.
  • The fix on this page was tested on the saved model answers, not in a new model run. Rows are matched by SKU, then by description. A number is right when it equals the printed value.
  • Peak memory is the peak memory footprint from /usr/bin/time -l: 6.0 GB for 2B. MLX itself reported 2.8 GB (2B) and 4.3 GB (4B).
  • The Tesseract script ran today on the same 10 pages, about 0.9 s a page on average. The Actor line is its build 0.1.44 code, run on the Mac on Nov 7, not on Apify.
Not tested
  • The big models in Sparrow's examples, such as Mistral Small 24B.
  • Ollama, the Sparrow server and its UI.
  • PDF input (by the code, the model loads once for a PDF without tables_only), tables_only, crop_size, or bounding boxes.
  • Real invoices, phone photos, handwriting, other languages.
  • The Actor's Markdown sent to a model.
Sources

Questions people ask

What is Sparrow OCR?

Sparrow, by Katana ML, pulls structured data out of documents with vision language models. sparrow-parse is its Python library. It runs models on MLX on Apple Silicon, on Ollama, or on cloud backends. It is GPL-3.0. Its README adds that it is free for open source projects and organizations under $5M revenue, with a commercial license for proprietary use.

Why did sparrow-parse drop my invoice number?

In sparrow-parse 1.6.3, when the model answers with plain JSON and no ``` fence, the cleanup step looks for a list of objects first. It keeps only that list, for example line_items, and drops every other field. Parse the answer with json.loads before that step.

Which model should I use with Sparrow on a Mac?

Of the two I tested, Qwen3-VL 4B at 4-bit. With the fix on this page, it got every field right on 10 test invoices, at 8.6 s a page. The 2B model was faster, but it broke its JSON on 3 of 10 pages and made up totals.