Skip to main content

Lakshana

PyPI CI License: MIT Python

लक्षण (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:

  1. What document types are in there. Clusters similar documents together via UMAP + HDBSCAN over a hybrid structural + semantic embedding.
  2. What fields each type has. Asks an LLM to infer a schema, then verifies field frequency across the cluster with grounding quotes.
  3. 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

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.

Metadata

Release files for lakshana 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lakshana 0.1.3
File Size Uploaded
lakshana-0.1.3.tar.gz 45.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for lakshana 0.1.3
File Interpreter ABI Platform
lakshana-0.1.3-py3-none-any.whl Python 3 none any Details

Total release size: 80.1 kB

Release files / lakshana-0.1.3.tar.gz

Download URL lakshana-0.1.3.tar.gz
Size 45.1 kB
Tags Source
SHA-256 checksum
How to use checksums
65f96b1d8db7d01de942334c8a7028ea161860c5ff33a5866a40224fc19d4c53
BLAKE2b-256 checksum
How to use checksums
7904674b14f48d317b56bd5daf10927c45b9685abba164338a6c2ca089e5e9aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / lakshana-0.1.3-py3-none-any.whl

Download URL lakshana-0.1.3-py3-none-any.whl
Size 35.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68efa0d568528d4a4aa0a9827ca6259e1545b54c686bab0b10d17cad1db74573
BLAKE2b-256 checksum
How to use checksums
02358faa4c0afb6eaec168b27853800b565a7576364478ca6fa22d5c978cda71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page