Zero-config schema discovery for document collections. Drop a folder of PDFs, get a JSON Schema.
Project description
Lakshana
लक्षण (lakṣaṇa, Sanskrit) — "defining characteristic, marker, distinguishing feature."
Zero-config schema discovery for document collections. Point Lakshana at a folder of mixed documents and it returns a JSON Schema for each document type it finds. No training, no labels, no manual schema design.
pip install "lakshana[openai]" # or [anthropic] · [google] · [all]
export OPENAI_API_KEY=... # or GROQ / ANTHROPIC / CEREBRAS / GOOGLE
lakshana analyze ./my_docs --output schema.json
There's also an interactive demo that walks through a real run, end to end, in the browser.
What it does
Given a folder of mixed documents — invoices, contracts, statements, forms, reports — Lakshana figures out:
- What document types are in there. Clusters similar documents together via UMAP + HDBSCAN over a hybrid structural + semantic embedding.
- What fields each type has. Asks an LLM to infer a schema, then verifies field frequency across the cluster with grounding quotes.
- A clean schema per type, in the format you want. JSON Schema, CSV headers, Markdown table, or a structured entity list — ready to drive downstream extraction.
It is the "tell me what I have" step that every document-extraction pipeline skips — and pays for later.
Highlights
- Zero schema design. Point it at a folder. Get back a typed schema with frequency and grounding for every field.
- No labels, no training. Pure clustering plus LLM inference. Works on 10 documents or 10,000.
- Runs anywhere. CPU is enough on a laptop; GPU is supported but not required.
- Bring your own LLM. Anthropic, OpenAI, Groq, Cerebras, Google, OpenRouter, Ollama, or any OpenAI-compatible endpoint.
- Mixed structured + prose. Works on form-style key-value documents and on prose narrative — the schema comes from both.
- Tested. 77 unit tests, CI green on Python 3.10 / 3.11 / 3.12.
Python API
from lakshana import discover
result = discover(
files=["./docs/inv1.pdf", "./docs/inv2.pdf", "./docs/contract.pdf"],
model="groq/llama-3.3-70b-versatile",
min_cluster_size=3,
)
for cluster in result.clusters:
schema = result.schemas[str(cluster["id"])]
print(cluster["name"], "→", [f["name"] for f in schema["fields"]])
Each field on the returned schema carries frequency, doc_count, and verified_against so you can see exactly how trustworthy it is.
Export the result in whichever format fits your downstream pipeline:
from lakshana import (
export_as_json_schema,
export_as_csv_headers,
export_as_markdown,
)
schema = result.schemas["0"]
export_as_json_schema(schema, name="Invoice") # standard JSON Schema
export_as_csv_headers(schema) # spreadsheet headers
export_as_markdown(schema, name="Invoice") # documentation / wiki
CLI
lakshana analyze ./docs --model groq/llama-3.3-70b-versatile --output result.json
How it works
parse → embed (structural + semantic)
→ cluster (UMAP + HDBSCAN)
→ label cluster (LLM)
→ infer schema (LLM)
→ verify field frequency across the cluster (LLM + grounding)
→ deduplicate and group fields semantically
→ export (JSON Schema / CSV / Markdown)
Every step has a graceful fallback. Every output traces back to real text in your documents.
Benchmarks
The repo ships with two reproducible benchmarks. Clone, set an API key, and run:
git clone https://github.com/mickyaero/lakshana && cd lakshana
export GROQ_API_KEY=...
python benchmarks/run.py --dataset synthetic # 50 docs, 5 generic types
python benchmarks/run.py --dataset bfsi # 35 Indian financial docs, 7 types
Reports ARI, NMI, V-measure, homogeneity, completeness, and cluster purity. See benchmarks/README.md.
Examples
examples/quickstart.py— discover schemas across the bundled dataset and print fields per cluster.examples/export_json_schema.py— export each cluster as a standard JSON Schema for downstream extraction, OpenAPI specs, or LLM tool contracts.
Why it exists
Most AI document-extraction tools assume you already know what fields you want. Real-world data isn't shaped that way — you get a hard drive of receipts, contracts, statements, and ???, and you have to figure out the shape before you can extract anything.
Lakshana is the discovery step that lets the rest of your pipeline be simple.
— Micky · @mickyaero
Contributing
Issues and PRs welcome. Especially:
- New LLM provider integrations (add to
src/lakshana/llm.py) - Real-world benchmark datasets (please anonymize before sharing)
- Examples in other domains (medical, legal, scientific)
pip install -e ".[dev]" && pytest to develop locally.
License
MIT — use it freely, including commercially.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lakshana-0.1.2.tar.gz.
File metadata
- Download URL: lakshana-0.1.2.tar.gz
- Upload date:
- Size: 41.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f859f3f648d505c9355a81763ef368abeb554de74cd18f6b7b5b320250bd8f17
|
|
| MD5 |
4fc5f5167a191b4c16894d097d348340
|
|
| BLAKE2b-256 |
b4ac16315212f2b801324ede3e1b3f2208059af10e6df930a186689f31050ac6
|
File details
Details for the file lakshana-0.1.2-py3-none-any.whl.
File metadata
- Download URL: lakshana-0.1.2-py3-none-any.whl
- Upload date:
- Size: 32.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
16c91497579bcb9482969120bc4329e152e6f42b6bf6cf5b34591b5ca65dc551
|
|
| MD5 |
a8b317234f30ed0268720efbb98d9660
|
|
| BLAKE2b-256 |
716ef4db7f6e94402dc4f1c99b68923c74d11105b9efd38eff75e083be20c908
|