Skip to main content

Convert handwritten documents into structured JSON with vision LLMs.

Project description

Handwriting JSON

Schema-guided handwritten document extraction for developers.

Handwriting JSON converts handwritten PDFs and images into structured JSON using vision LLMs and optional schema guidance. It is provider-agnostic through LiteLLM, so you can route extraction through models from Anthropic, OpenAI, Gemini, Mistral, and other supported providers.

Originally, this project came from OmmSai, a prescription extraction system built to process roughly 15,000 handwritten prescription files for a charitable healthcare event. This repository generalizes that work into a clean open-source Python package and CLI.

Features

  • Extract structured JSON from handwritten PDFs and images.
  • Guide extraction with JSON Schema or an example JSON object.
  • Use multiple vision LLM providers through LiteLLM.
  • Process one document or a directory of documents from the CLI.
  • Use the same extraction path from Python code or the command line.
  • Keep prescription extraction as an optional preset, not the product boundary.

Install

pip install handwriting-json

For local development:

git clone https://github.com/ramdhavepreetam/handwriting-json.git
cd handwriting-json
python3 -m pip install -e ".[dev]"

Provider credentials are configured through the environment variables expected by LiteLLM for the model you choose.

Python API

from handwriting_json import extract

result = extract(
    "examples/sample.pdf",
    model="anthropic/claude-sonnet-4-5",
    schema={
        "name": "",
        "date": "",
        "items": []
    },
)

print(result.data)

CLI

handwriting-json extract --input form.pdf --model anthropic/claude-sonnet-4-5
handwriting-json extract --input form.pdf --schema examples/form_schema.json --output result.json --model anthropic/claude-sonnet-4-5
handwriting-json batch --input-dir ./forms --output results.jsonl --model anthropic/claude-sonnet-4-5
handwriting-json version

During development, the module form also works:

python3 -m handwriting_json --help

Schema Guidance

You can pass a formal JSON Schema or a simpler example JSON object.

{
  "name": "",
  "date": "",
  "items": [
    {
      "label": "",
      "value": "",
      "confidence": ""
    }
  ]
}

The schema is injected into the prompt so the model knows the desired output shape. Formal JSON Schema responses are also validated after extraction.

Positioning

This is not just OCR. The goal is schema-guided handwritten document extraction: turning messy handwritten documents into application-ready JSON.

Good use cases include intake forms, field notes, inspection sheets, surveys, prescriptions, school forms, KYC forms, and scanned operational paperwork.

Development Checks

python3 -m pytest tests
python3 -m handwriting_json --help
python3 -m handwriting_json version

Roadmap

  • V1: Python package, CLI, schema guidance, LiteLLM provider abstraction.
  • V1.1: checkpointed batch processing, validation repair loop, Docker image.
  • Later: REST API mode, OCR fallback, cost reporting, more domain presets.

License

MIT

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

handwriting_json-0.1.0.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

handwriting_json-0.1.0-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file handwriting_json-0.1.0.tar.gz.

File metadata

  • Download URL: handwriting_json-0.1.0.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.1

File hashes

Hashes for handwriting_json-0.1.0.tar.gz
Algorithm Hash digest
SHA256 08821c531d4bd8198155f743af84fd0f4f4f47ecdbdd3da7ceec038dc7ff1b70
MD5 608301b70d3677f30e447ca77530e337
BLAKE2b-256 0a3c5c6f4dbdede300a764e0c0a2d2df1a9f54356a54958b0f4d77e4f80dae88

See more details on using hashes here.

File details

Details for the file handwriting_json-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for handwriting_json-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dad00164d0b2405313195242cda9a40d46e6bc3f5c90392e5debf281e3500795
MD5 cf90525dfae2f5cc6d3c76e5db44289d
BLAKE2b-256 f7df3b52a84ca981ffc0aa76c13a8e621c83c98f5bd913478a94900ad77638ee

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page