Skip to content

Repository files navigation

qleric

Pull facts out of PDFs and Word docs, with proof.

Every answer comes with the exact words it came from, the page, and where they sit on that page. If qleric can't point to it, it doesn't answer.

Contract page with highlighted spans, each joined by a line to its JSON field with quote, page and position

Every value qleric returned, highlighted on the original page — each highlight wired to its field, quote, and position.

Why

The usual way to read documents with AI is to send the whole file to a big model and hope. That's slow and expensive, and a right answer looks exactly like a confident wrong one.

qleric works the other way round:

  1. Plain code goes first. Dates, totals, invoice numbers, emails, phone numbers, table rows, governing-law clauses. It's free, instant, and works offline.
  2. A small model handles what's left, like names, skills or who the seller is. It only sees the few paragraphs that matter, not the whole document.
  3. A big model comes in only for fields you've marked as hard, and only if the small one failed.
  4. Every answer gets checked against the document, whichever step produced it. If the quote isn't really there, the answer is thrown out.

The goal is to keep shrinking the share of work that needs a model, until reading the document costs close to nothing. What's left is a clean set of facts with sources attached, and bigger models can reason over that cheaply instead of re-reading 200 pages every time.

Funnel: document in, plain code, small model, then big model, with a full-width check against the page

What you get

  • Proof. Every value comes with its quote, page number and position, ready to highlight or check.
  • Honest blanks. If something isn't in the document, you get null with a reason, never a made-up answer.
  • Known cost. Every response lists model calls, tokens and dollars spent. With no key the cost is $0, because no model gets called.
  • No key needed to start. Everything plain code can do runs locally. Add your own key for any OpenAI-compatible provider (OpenAI, Claude, Gemini, or a local model through Ollama) when you want the rest.
  • Your documents stay with you. With no key, nothing leaves your machine. With a key, the model gets the relevant passages, not the whole file.

Try it

pip install -e .
qleric invoice.pdf --pack invoice                # JSON to stdout
qleric contract.pdf --pack contract --annotate   # also writes a highlighted PDF

What comes back (trimmed):

{
  "fields": {
    "total_amount": {
      "value": "$1,240.00",
      "verbatim": "Total Due $1,240.00",
      "page_number": 1,
      "bbox": [[72.0, 148.6, 171.7, 163.7]],
      "grounded": true,
      "source": "local",
      "confidence": "high"
    },
    "seller": { "value": null, "grounded": false, "note": "keyless (deep=False): abstained without model call" }
  },
  "meta": { "grounding_rate": "5/8", "cost": { "calls": 0, "cost_usd": 0 } }
}

source tells you which step answered: local, table, pii, llm-small or llm-big.

To use a model, copy example.env to .env and set API_KEY (plus MODEL and BASE_URL if you're not on OpenAI). Set MODEL_BIG if you want the escalation step.

Other ways to run it:

python api.py      # HTTP: curl -F [email protected] -F pack=invoice localhost:5000/analyze
docker build -t qleric . && docker run -p 5000:5000 qleric
from qleric import parse, query
from qleric.packs import INVOICE_FIELDS

data = open("invoice.pdf", "rb").read()
result = query(parse(data, "pdf"), INVOICE_FIELDS, data)

The HTTP server spends your model key on every request. If you expose it, set API_TOKEN and put it behind a proxy.

Packs

A pack is a list of fields for one kind of document. These come built in:

pack finds
invoice number, dates, total, tax, seller, buyer, line items
resume name, title, contact details, experience, education, skills
pii every email, phone, SSN, card number and IBAN, with positions ready for redaction
contract key dates, governing law, renewal, termination, liability caps and about a dozen other common clauses

Financial statement tables are available from Python (FINANCIAL_FIELDS). That one is early.

Your own fields are plain dictionaries. Give each one a name, a strategy, and some hints:

fields = [
    {"name": "po_number", "strategy": "local", "anchors": ["po number", "purchase order"]},
    {"name": "payment_terms", "strategy": "llm", "hint": "when and how payment is due"},
]

The full list of field options is in qleric/packs/__init__.py.

Where it stands

On the built-in test set of 105 messy synthetic documents, with no model at all:

  • 400 of 537 fields found by plain code, all of them correct, all of them with proof
  • 0 answers that pointed to the wrong place in the document
  • the other 137 (names, skills, sellers) come back as honest blanks until a model is allowed in

Run it yourself with python evals/eval.py samples/corpus/corpus.jsonl. You can also check it against your own files: put PDFs in samples/real/ and expected answers in evals/real_truth_local.py, then run python -m evals.validate_real. Git ignores both, so they stay on your machine.

Keyless results per field type: share of fields answered by plain code at zero cost

Status

Early and moving fast. The API may change. MCP tools for plugging qleric into your own assistant (python -m qleric.mcp) are experimental.

Known gap: when you ask for a field the document doesn't have, plain code can sometimes latch onto a similar-looking line instead of returning a blank. For example, a po_number request on an invoice with no PO came back with the invoice number. The quote is always real text from the page, but it can be the wrong text. Check results on new field types until this is fixed.

MIT licensed.

Releases

Packages

Contributors

Languages