v0.1.0 Open source · Apache-2.0 · Python 3.10+

PDFs in. Typed data and a verdict out.

nirmala pulls Pydantic models out of messy real-world PDFs, then proves every value against the page and your own rules, so each record arrives marked approve, review or reject, with the reasons attached.

$ pip install nirmala Read the docs Star on GitHub
motor_policy_schedule.pdf · synthetic sample
numberSGI/MT/26/0041977100verbatim · printed on p. 1
insuredKapil MittalMR. KAPIL MITTAL100snapped to the printed text, honorific kept
start2026-03-14100date · printed as 14-Mar-2026
premium5041.00100hint pulled in p. 9 · net + GST = total ✓
kindCar packageMotor94choice snapped · judge confirms
verdict–pending
value found on the pagewhat the model said, corrected

Your schema is the prompt. Your rules are the gate.

Describe the fields once in Pydantic. Write the checks your business already runs, in whichever form suits whoever owns them.

from pydantic import BaseModel
import nirmala
from nirmala import field

class Policy(BaseModel):
    """the insurance policy schedule"""
    number: str = field("Policy number", verbatim=True, critical=True)
    insured: str = field("Insured", verbatim=True, prefixes=["MR."])
    start: date = field("Policy start date", critical=True)
    premium: Decimal = field("Total premium", hint=r"total premium")
    kind: str = field("Line of business", choices=["Motor", "Health"])

result = nirmala.extract(
    "policy.pdf", Policy,
    rules=nirmala.load_rules("rules.yaml"),
    gate=nirmala.Gate(field=80, average=90),
)
result.verdict.decision   # 'approve'

Fields describe themselves

verbatim, choices, hint and critical sit on the field, next to its type. The prompt is built from them.

Rules in three registers

Python for exact logic, plain English for judgment, YAML for the people who own the policy. A strict allow-list parses every expression.

Any model, no keys in code

A private opencode serve starts on demand and reaches every provider you've signed in to. Or point it at any OpenAI-compatible URL.

Built for documents that fight back

Every row here is a failure mode the original production pipeline had to handle.

When this happensnirmala does this
The model normalizes a name"Kapil Mittal" for MR. KAPIL MITTALSnaps it to the exact printed span with verbatim=True; unmatched values are flagged in notes, never trusted.
The PDF is a scanno text layer at allRenders the first pages to images and reads them with a vision model, through the same schema.
It's password-protectedthe customer's date of birth, usuallyTries candidates from your list, function or vault via passwords=; raises PasswordRequired when none fit.
Five attachments, one is the policyplus two byte-identical copiesDrops duplicates, asks the model which file is the target, and stops at UNCERTAIN instead of guessing.
The total is on page 9after eight pages of termsA field hint regex pulls that page into the prompt; everything else stays within the page budget.
The judge times outor answers in the wrong typeFails closed: unscored fields count as 0 and the record goes to review. No error path can approve.

Three outcomes, each one explained

Values printed on the page score 100 without a model call. Everything else is scored by the judge and held to your gate.

approve

Every critical field clears its threshold, the average clears the gate, and no blocking rule failed.

review

A blocking rule failed, a critical field is missing or doubtful, or the judge was unreachable. verdict.blockers lists which.

reject

A rule you marked severity="reject" failed, such as an end date before the start date.

nirmala started as the extraction engine of an insurance operations pipeline that reads policy PDFs from many insurers and writes them into a CRM. The parts that kept bad data out are what's open-sourced here.

Stop trusting extraction. Start checking it.

Point it at a PDF and get data plus the reasons to believe it. Apache-2.0, no telemetry, your model.

$ pip install nirmala Get started View on GitHub