Skip to main content
A Python CLI that extracts payment details from invoice PDFs. This is a practical example of building local AI tools with no cloud costs, no network latency, and no data privacy loss.
Invoice parser architecture diagram

What you’ll learn

In this example, you will learn how to:
  • Set up local AI inference using llama.cpp to run Liquid models entirely on your machine without requiring cloud services or API keys
  • Build a file monitoring system that automatically processes new files dropped into a directory
  • Extract structured output from images using LFM2.5-VL-1.6B, a small vision-language model

Prerequisites

You will need:
  • llama.cpp to serve the Language Models locally
  • uv to manage Python dependencies and run the application efficiently
brew install llama.cpp
Verify llama-server is available:
which llama-server

How to run it

1

Clone the repository

git clone https://github.com/Liquid4All/cookbook.git
cd cookbook/examples/invoice-parser
2

Choose a mode

The tool supports two modes: watch (continuous monitoring) and process (one-shot).The tool automatically starts and stops llama-server for you — no need to run it separately.

Watch mode

Run it as a background service that continuously monitors a directory and automatically parses invoice images as they land in the folder:
uv run python src/invoice_parser/main.py watch \
    --dir invoices/ \
    --image-model LiquidAI/LFM2.5-VL-1.6B-GGUF:Q8_0 \
    --output bills.csv \
    --process-existing

Process mode

Process specific files or folders and exit:
uv run python src/invoice_parser/main.py process \
    --image-model LiquidAI/LFM2.5-VL-1.6B-GGUF:Q8_0 \
    invoices/
If you have make installed, you can run the application with:
make run       # watch mode
make process   # one-shot process mode

Results

You can run the tool with a sample of images under invoices/:
uv run python src/invoice_parser/main.py process \
    --image-model LiquidAI/LFM2.5-VL-1.6B-GGUF:Q8_0 \
    invoices/
Or with make:
make process
The model correctly extracts all 4 out of 4 invoices:
FileUtilityAmountCurrency
water_australia.pngwater68.46AUD
Sample-electric-Bill-2023.jpgelectricity28.32USD
castlewater1.pngwater436.55GBP
british_gas.pngelectricity81.31GBP

Next steps

The model works perfectly out-of-the-box on our sample of invoices. However, depending on your specific invoice formats and layouts, you may encounter cases where the extraction is not accurate enough. In those cases, you can fine-tune the model on your own dataset to improve accuracy. Check out the fine-tuning notebook for Vision Language Models to learn how.

Source code

View the complete source code on GitHub.

Build docs developers (and LLMs) love