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.
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'
from nirmala import rule, NLRule
# exact business logic, in Python
@rule(field="premium", when="kind == 'Motor'")
def premium_adds_up(ctx):
"Premium must equal net + GST"
return abs(ctx["net"] + ctx["gst"] - ctx["premium"]) < 1
# a judgment call, checked by a judge model
one_year = NLRule(
"The policy period is exactly one year",
field="end", severity="warn",
)
pipe = nirmala.Pipeline(
rules=[premium_adds_up, one_year],
gate=nirmala.Gate(),
judge=nirmala.Judge(model="opencode-go/kimi-k3.1-pro"),
)
# owned by the ops team, reviewed like code
rules:
- name: idv_for_motor
when: insurance_type == 'Motor'
require: present(idv) and idv > 0
message: Motor policies must print an IDV
- name: period_order
require: end_date > start_date
severity: reject
- name: premium_math
judge: The total premium equals the base premium plus GST.
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.
verbatim=True; unmatched values are flagged in notes, never trusted.passwords=; raises PasswordRequired when none fit.UNCERTAIN instead of guessing.hint regex pulls that page into the prompt; everything else stays within the page budget.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.
Every critical field clears its threshold, the average clears the gate, and no blocking rule failed.
A blocking rule failed, a critical field is missing or doubtful, or the judge was unreachable. verdict.blockers lists which.
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.