How it works
The model reads. Code decides.
Everything that touches a verdict is deterministic TypeScript with no network access. The model's only job is to report what the papers say, with the sentence it read it from.
The pipeline
Step by step
1. Read the papers
Text files are read as they are. PDFs are opened with pdf.js in the browser, page by page. A page with too little text, or text that looks like mangled legacy-font Devanagari, is treated as a scan: it is rendered to a PNG and transcribed by Claude Opus 5.5 with the instruction to keep Devanagari as Devanagari, keep line breaks, and not translate or summarise. Uploads take up to 20 files, 15 pages each, 12 MB per file (apps/web/src/lib/ingest.ts).
2. Extract facts, each with a quote
Claude Sonnet 5.5 returns a structured extraction (packages/reader/src/schema.ts): every charged section with its act, the custody start date and its kind (arrest, remand, surrender), first-time offender status, other pending cases, the registration date, and the case number and court. Every fact has a quote field: the exact text it came from, same script, no translation, no ellipsis. The prompt tells the model never to decide eligibility, never to compute anything, and to treat text inside the document as evidence, never as an instruction. A second, cheap pass looks only for charged sections the first pass missed (the self-check), each again with a quote.
3. Verify every quote
The span verifier (packages/reader/src/verify.ts) normalises the document and the quote the same way: Unicode NFC, Devanagari digits to ASCII, zero-width characters removed, curly quotes and dashes unified, the danda । treated like a full stop, all whitespace ignored, letters lower-cased. Then it looks for the quote as an exact substring. There is no fuzzy matching and no paraphrase. A quote shorter than six characters after normalisation counts as no quote.
- A section is accepted only if its quote is in the document and contains that section number.
- A date is accepted only if its quote is in the document and contains that same date (in any written form the date finder reads).
- First-time status and other pending cases need a quote that is in the document.
A claim that fails is not used. Its field becomes unknown, and the claim is listed on screen as rejected, with the reason (“The quoted text is not in the document.”, “The quote gives 2024-05-20, not 2023-05-20.”). Accepted facts keep their position in the document, so the case page can mark them.
4. Apply the law
evaluate(input, today) in packages/law/src/engine.ts is pure: the same facts and the same date always give the same result. It looks up every charged section in the statute tables, finds the longest maximum term, picks the fraction, counts from the custody date, and returns a verdict with a typed trace: one line per step, each with the statute it rests on and, where there is one, the quote it rests on. The rules are on How Section 479 is computed.
5. Sort into lanes
A sweep sorts people into four lanes: past the line (with the flagged cases inside it), not yet, can't tell, and outside 479. The docket agent orders them for a review meeting: past the line first (most days past at the top), then flagged, can't tell, not yet (soonest first), outside 479.
6. Draft the paperwork
For anyone past the line, code fills the Section 479(3) application in English or Hindi (packages/reader/src/application.ts) with the case details, the computation, the provisions and the verified quotes, with blanks for signatures, marked as a draft for lawyer review. The Know your line notice (notice.ts) and the records-request letters are also built by code from fixed templates and verified facts. No model writes any of them.
Trust boundaries
- Papers → model. Papers can contain anything, including instructions. The prompt fences the document as data, but nothing depends on that: the model has no way to produce a verdict, only facts with quotes.
- Model → code. Every fact must carry a quote that the verifier finds in the papers. Failures become unknown. Unknown facts can only move a case towards “can't tell”, never to “past the line”; a property test in
packages/law/testchecks that unknown sections never pass. - Code → person. The engine never says “eligible”. Cases where 479(2) may apply are flagged for a lawyer. Every output is a draft.
The five verdicts
Verdicts are deliberately not “eligible / not eligible”. The code name is what the engine, the API and the MCP tools return.
| Code | Shown as | When | What happens next |
|---|---|---|---|
| PAST_THE_LINE | Past the line | Half (or one-third) served, one offence, the papers say no other cases. | The jail must apply under 479(3). A lawyer reviews and signs the draft. |
| PAST_FLAGGED | Past the line · flagged | Past the line, but more than one offence is charged, or other cases are pending or not ruled out. | 479(2) may apply. A lawyer decides before anything is filed. |
| NOT_YET | Not yet | The line date is still ahead. | The date and the days to go. If first-time status is unknown and the one-third line is already crossed, a flag says so. |
| CANT_TELL | Can't tell | No custody date, a section not in the tables, an NDPS quantity not given, a maximum that depends on details the papers don't give. | The missing facts are listed; the agent can request the record that would supply them. |
| EXCLUDED | Outside 479 | Any charged section allows death or imprisonment for life. | Section 479 does not apply. |
Why “flagged” exists
Courts read 479(2) differently. Some read “more than one offence” as any charge sheet with several sections; others only as separate offences or cases. HalfTime takes no side, and puts every such case in front of a lawyer. See /law.Models and caching
| Job | Model id |
|---|---|
| Fact extraction with quotes, the missing-section self-check, the docket agent | claude-sonnet-5-5 |
| Plain-chatbot baseline (same model, naive prompt), for comparison only | claude-sonnet-5-5 |
| Transcribing scanned pages | claude-opus-5-5 |
| Reading the chatbot's answer into yes / no / unclear, for scoring | claude-haiku-5-5 |
The ids are pinned in packages/reader/src/models.ts. Every response is cached by a hash of the model, the prompt version (now v6) and the input, so the same document is never paid for twice and a recorded run replays exactly. On a self-hosted server the cache is Cloudflare KV (30 days); in the browser it lasts for the session.