Caliper
Air-gapped agentic workbench for industrial documents. It reads P&IDs, scanned inspection reports and SOPs, computes deterministically, cites the exact region it used, and refuses when it can’t.
- Python
- FastAPI
- React
- Ollama
- Qdrant
540
tests passing, 0 failing
24/24
air-gap checks with Wi-Fi off
3
signed deliverables per task
An agent that sounds confident while making up numbers is strictly worse than no agent at all.
why I built it01How it flows
- 1Upload the paperworkscans, SOPs, P&IDs
- 2Hand the agent a taskplan → retrieve → verify
- 3Every number checked against its sourcecitation gate
- 4A named reviewer signs offapproval gate
- 5Download the deliverables.docx · .xlsx · .pptx
02The fun part3 problems
The citation gate
1/3A signed note carried 7.45 mm/s, cited to a page that only stated the 4.5 mm/s limit. Now a value ships only if its own source states it, unit included, and that exact bug is pinned by a test.
finding_support.pyMonitoring that failed open
2/3When psutil couldn't see a process, the air gap was reported clean. Now there are four verdicts, and "couldn't look" never counts as a pass.
sovereignty/Three zone tables, one machine
3/3The dashboard said Zone C while the agent said Zone B for the same reading. I merged three boundary tables into one source of truth.
vibration_zones.py1def value_is_stated_in(text: str, value: Any, unit: Optional[str] = None) -> bool:2for variant in _number_variants(float(value)):3pattern = rf"(?<![\d.]){re.escape(variant)}(?![\d.])"4for m in re.finditer(pattern, haystack):5tail = haystack[m.end():m.end() + 12].lower()6if re.match(rf"\s*{re.escape(unit_norm)}", tail):7return True
03What broke
- The database path is relative, so starting from the wrong folder quietly creates a second, empty database.
- The ASME and ISO reference tables are transcribed, not verified, and every output says so.
- 18 tests fail instead of skipping when Ollama is stopped.
The leftovers
It took the whole of September.
The funny part: a week before the deadline I told my team the project was built. I hadn't started. I was still researching.
04Things people ask
What's the stack?
FastAPI backend, React frontend (no framework — just React + Lucide), SQLite for tasks and audit chain, Qdrant for vector search, Ollama for local inference, LiteLLM as a routing registry, docling for document structure, RapidOCR for degraded scans.
Why not just use GPT-4 or Claude?
The problem was specifically offline operation at a refinery. MRPL's setting means no cloud API. Everything runs on a local M1 with 8 GB unified memory, Wi-Fi off, and the sovereignty panel confirms it with three independent measurement methods.
Can I try it?
The code is on GitHub. To run it you need Python 3.12+, Ollama with specific models, and a macOS or Linux machine (or Docker for the sandbox tier). The README has a full run guide, and scripts/verify_flagship.py will tell you if everything works before you demo it.
What's the citation gate?
A finding row only appears on a signed deliverable if its cited page actually states that row's value with its unit — not just that the citation resolves. This caught a real bug: a 7.45 mm/s measurement whose cited page stated only the 4.5 mm/s limit. The gate has a pinned test for that exact case.
What was the hardest part?
Making the sovereignty monitoring fail closed instead of open. The original code caught AccessDenied, returned an empty connection list, and reported the air gap as clean. A system that calls "I couldn't look" the same as "I looked and it's fine" is worse than no monitoring. The four-verdict model (including UNVERIFIED and UNAVAILABLE as distinct states) is the fix.
What does "air-gapped" actually mean here?
Ollama is bound to loopback only (127.0.0.1:11434). LiteLLM's cost-map fetch is forced to the bundled local copy. HuggingFace is put in offline mode. A CPython audit hook fires on any socket.connect() call and halts inference. The sovereignty panel measures cumulative external bytes per process and shows the result. You can falsify the claim with a network monitor in about ten seconds — that's the point.
Why build a custom model router on top of LiteLLM?
LiteLLM routes by load-balancing and fallbacks. I needed the router to produce a sentence a judge can follow: "Scanned raster input with no text layer → vision model; qwen3-vl:4b, 3.61 GB resident, 8.36 tok/s median." LiteLLM can't produce that because it doesn't know what inputs determined the choice. The router in model_router.py decides on checkable facts (text layer present/absent, task verb, MIME type) and pulls every number from benchmarks.json rather than writing adjectives.
What are the real limitations?
The ASME B31.3 and ISO 10816 reference tables are transcribed, not verified — nobody opened either standard. The wall thickness formula is the standard one; the constants feeding it are not guaranteed correct. Kernel-level egress enforcement (nftables) is Linux-only and correctly reported as UNAVAILABLE on macOS. The UI end-to-end test is a declared skip — every selector in it was invented and it asserted behaviour the product doesn't have. All of this is in the README at the top, not in a footnote.
Why publish a self-audit before the demo?
Because the claim is that the system is honest about what it can't do. Publishing 235 findings, including six that turned out to be false positives after adversarial verification, is more credible evidence of that than asserting it. A limitations list you volunteer is evidence of rigour; one discovered by a judge is a map of where to attack.
What does "refuses" mean in practice?
When the agent proposes a value it can't source — either the citation resolves to nothing (ORPHAN), or the resolved text doesn't state that value with its unit — the row is omitted from the signed note. The note says the register is short and by how much. An omission a reviewer can see is better than a number a reviewer can't check.
What would you do differently?
Make the database path absolute. Right now config.py:23 is relative to the working directory, so starting the backend from the wrong folder silently creates a second empty database. The failure is subtle — Qdrant is on an absolute path so citations still resolve — and that makes it hard to notice during setup. One absolute path in config would have saved several confusing minutes.
The whole write-up6 min read, for the curious
The itch
The problem statement (SIH 2026, PS 26117, posed by MRPL) was about industrial inspection workflows: engineers at a refinery have stacks of scanned PDFs — P&IDs, inspection reports, SOPs — and turning those into signed engineering deliverables is slow and error-prone. The natural instinct is to throw an LLM at it. The problem is that a document carrying a two-party engineering signature block needs to be verifiable, not just fluent. An agent that sounds confident while making up numbers is strictly worse than no agent at all.
So the question I ended up caring about was: how do you build a system where every number on a signed document has a traceable source, and the system refuses when that source doesn't exist?
What it does
A user uploads scanned inspection reports, SOPs, or P&IDs through a document workbench. They then hand a task to an agent — "analyse this pump inspection report", "calculate the required wall thickness for this line". The agent runs a deterministic plan → retrieve → tool-call → verify → output loop, showing each step live in the UI as it runs.
At the end they get real deliverables: a hash-chained approval note (.docx), a finding register (.xlsx), and a briefing deck (.pptx). Before any of that can be downloaded, a named reviewer has to sign off through the Approval Gate. The whole thing runs with the Wi-Fi off. A sovereignty panel measures outgoing bytes three independent ways and shows the result.
How it works
Upload → OCR/docling extraction → Qdrant vector index
↓
Task → Orchestrator (plan) → Agent loop → Citation gate → Deliverables → Approval Gate
↓
Sandbox (Seatbelt / bwrap / Docker)
Backend is FastAPI + SQLAlchemy on SQLite. One worker only — the audit chain is appended under a process-wide lock and two workers can fork it, which makes the audit verification screen report is_valid: false. That's a bug I chose to accept and document rather than pretend it can't happen.
Document understanding uses docling for structure and table extraction, RapidOCR (PP-OCR ONNX, no cloud) as a pre-pass on degraded scans, Tesseract as a fallback, and Apple's Vision OCR (ocrmac) when the device supports it. PDFs are rasterised with pypdfium2 — I switched from PyMuPDF after it came up as an AGPL procurement finding in a PSU context.
Models run entirely through Ollama on loopback. LiteLLM acts as a registry that knows how to reach a model by alias. Selection lives in a separate model_router.py that picks based on checkable facts: does this PDF have a text layer? Is the task verb "write a script" or "read a nameplate"? The router's reason string — the one a judge reads — pulls numbers directly from benchmarks.json, which has median tokens/second from 5-trial cold-start runs. It used to write fixed adjectives like "fast" that didn't change when the model did.
Embeddings use a 307 MB Gemma model (embeddinggemma:300m-qat-q4_0), always kept resident alongside the active LLM. OLLAMA_MAX_LOADED_MODELS=2 in .env.ollama, because otherwise every RAG call evicts the main model and the next inference cold-starts from disk.
Sovereignty panel runs four tiers: per-process socket inspection via psutil, cumulative external byte counters via nettop, an in-process CPython audit hook that latches and halts inference on any socket.connect(), and kernel-level nftables enforcement (Linux only — correctly reported as UNAVAILABLE on macOS, never counted as a pass). The four-verdict model (ENFORCED / VIOLATED / UNVERIFIED / UNAVAILABLE) exists because two verdicts aren't enough to be honest with. "We could not look" has to mean something different from "we looked and it was clean."
Frontend is React with no framework dependencies beyond React itself and Lucide icons. Routing, state, and fetch are all vanilla. The colour palette bans green — the clean state is teal — so a non-pass can never be mistaken for a pass by colour alone.
The fun part
The citation gate. In Phase 9 I found an unsourced measurement on a signed approval note: a bearing vibration reading of 7.45 mm/s, with a citation that resolved perfectly — to a page stating only the 4.5 mm/s limit. One citation covered two values and sourced the wrong one. The document was asking a reviewer to sign for a number with nothing behind it.
The structural problem was that extract_numeric_readings() returned {parameter, value, unit, raw} with no citation field on a reading at all. Citations lived in a separate document-level block. Nothing ever connected a row to its source; the appearance of support came from the two being near each other on the page.
The fix is finding_support.py: a value reaches a signed note only if its own citation resolves and the resolved text actually states that value with its unit. I check both because resolution alone isn't evidence — you can always give the limit's citation to the measurement, and it will resolve perfectly. The 7.45 mm/s case is pinned by a test that constructs the exact corpus that produced it.
def value_is_stated_in(text: str, value: Any, unit: Optional[str] = None) -> bool:
for variant in _number_variants(float(value)):
pattern = rf"(?<![\d.]){re.escape(variant)}(?![\d.])"
for m in re.finditer(pattern, haystack):
tail = haystack[m.end():m.end() + 12].lower()
if re.match(rf"\s*{re.escape(unit_norm)}", tail):
return True
The number boundary uses (?<![\d.]) rather than \b because \b treats a decimal point as a word boundary — which means 4.5 would match inside 14.53.
The sovereignty monitoring failure mode. The original sovereignty code caught AccessDenied from psutil, set the connection list to [], and reported the air gap as clean. That's a monitoring system that fails open: if it can't see the process, it calls it safe. The fix was the four-verdict model and the rule that "Not listed" and "not running" are different things. Tier 2 (nettop) separately confirms the process is actually running before trusting a zero.
Three conflicting vibration zone tables. At one point the system had three different boundary sets for ISO 10816. The dashboard said Zone C for a 3.5 mm/s reading, the agent trace said Zone B, at the same moment, for the same machine. I consolidated on the one set that had a stated machine group in a comment (ISO 10816-3 Group 1 rigid), removed AudioVisualizer's outlier set, and wrote vibration_zones.py as the single source of truth. The docstring is honest about what this fixes (an internal contradiction) and what it doesn't (the tables are still transcribed-unverified; ISO 10816-3 wasn't opened during this project).
What broke / what I'd change
The database path is relative to the working directory. config.py:23 sets DATABASE_URL = "sqlite:///./data/workbench.db". Start the backend from the repo root instead of backend/ and you get a second, empty database with no reviews table. The Qdrant path is absolute and unaffected, so citations still resolve against the real index — which makes the failure subtle rather than immediate. I'd make both paths absolute.
The ASME B31.3 and ISO 10816 reference tables are transcribed and unverified. Nobody on this project opened either standard. The wall thickness formula is correct; the input values feeding it are not guaranteed to be. Every output carries a disclaimer that names which rows are in the TRANSCRIBED-UNVERIFIED class, and S (allowable stress) sits in the denominator, so overstating it understates required wall thickness — the unsafe direction. That's a real limitation on anything beyond a demo.
The 18 tests that need Ollama running fail (rather than skip) when the model runtime is stopped. That's a wart I named in the README rather than fixed.
Numbers
- 540 passed, 1 skipped, 0 failed — full suite run with the complete stack up, on an M1 / 8 GB, in 133 s (2026-09-22)
- 24/24 sovereignty checks pass with the radio off at the hardware level —
verify_offline_result.jsonin the repo - 281 test functions across 26 test files
- 5-trial benchmarks for every model in
benchmarks.json, measured at cold start - 12 flagship-path steps covered by the demo script, each with measured durations
- 23 file tool tests, 16 of them refusals (symlinks, path traversal, write outside root)
- 3 OCR adapters in priority order: Apple Vision → RapidOCR → Tesseract
- 4 sovereignty verdict states: ENFORCED / VIOLATED / UNVERIFIED / UNAVAILABLE
- 3 deliverable formats:
.docxapproval note,.xlsxfinding register,.pptxbriefing deck
Leftovers
It took the whole of September.
The funny part: a week before the deadline I told my team the project was built. I hadn't started. I was still researching.
