Why doesn't this invoice reconcile? Trailmark follows an invoice through the accounts-payable trail (purchase order, goods receipt, invoice, payment, bank line, our GSTR-2B) as a Relate graph. It points at the exact link that is broken and shows the path that proves it.
Live demo (runs in your browser, nothing to install) · Demo video (1:36) · Python, CLI and AI-agent tools below
Sample data. Every vendor, person, GSTIN, bank account and amount in this repo is invented. GSTINs carry
SAMPLin the PAN slot and IFSC codes start withSMPL, so nothing can be mistaken for a real registration or account.
Open any reconciled invoice in the live demo (or press Break the books) and cut its receipt link with the scissors. The link is removed from the Relate graph in your tab with a real DELETE, all six checks run again in a few milliseconds, and the invoice becomes an exception with the same receipt offered back as the fix. The test suite does the same for all 19 such invoices on every push: each cut is caught exactly once and nothing else changes (cypher/cuttable.cypher picks them, test_8 in tests/test_trailmark.py checks them).
- Check 3 follows a chain of bank reversals with a quantified path pattern (
{1,3}); in SQL that is three self-joins or a recursive query. - Check 6 looks at every 1 to 3 hop path from a payment to any employee over five relationship types at once: who approved it, who entered the new bank details, who owns the receiving account (side by side with SQL below).
- Check 1 runs a vector search and graph rules in one statement. On
INV-1042the text match scoresGRN-5404highest (1.00), and the graph rules it out because it is already received againstPO-7604; the app draws that ruled-out receipt struck through, next to the PO it belongs to. - One file holds it all:
store/trailmark.rlis committed. The browser, the CLI and the AI-agent server run the same.cypherfiles against it, and a fix made from the CLI or an agent is written into it with who made it and why.
At month end, an accounts-payable team ties out every invoice: was it ordered, was it received, was it paid, did the money really leave the bank, did the supplier report it for GST? Each answer sits in a different ledger. When something does not tie, someone opens five spreadsheets and follows the trail by hand.
The trail is a graph, and the hard breaks are only visible when you can walk it:
| # | Break | What the graph has to do | Sample |
|---|---|---|---|
| 1 | Invoice has no goods receipt, but the receipt exists, keyed against a PO number that does not exist | find the gap on Invoice → PO ← Receipt, then vector search over receipt item text (same vendor) for lookalikes, and let the graph reject the ones already received against another PO or with a different quantity |
INV-1042 |
| 2 | Billed more than was received | sum many receipts and many invoices that meet at one PO | INV-1038 |
| 3 | Marked paid, but the money came back | one payment settles three invoices, leaves the bank as two debits, and one debit is reversed. The reversal chain is a quantified path pattern | INV-1036 |
| 4 | Same invoice paid twice | two invoice nodes with one vendor, one normalised number (BOS/889 = BOS-889) and one PO, each with its own payment and bank line |
INV-1040 |
| 5 | Tax credit claimed, supplier never filed | an invoice with no REPORTS link from a line of our GSTR-2B (the supplier never put it in their GSTR-1), while the same supplier's other invoices have one |
INV-1041 |
| 6 | Large payment to a just-changed bank account that belongs to an employee | every 1-3 hop path from the payment to any employee, over five relationship types: who approved the payment, who entered the new bank details, who owns the receiving account | INV-1037 |
The other 20 invoices reconcile, so the checks are quiet when nothing is wrong. The six findings put ₹12,89,516 at risk.
The same model as a Mermaid chart
flowchart LR
PO[PurchaseOrder] -- PLACED_WITH --> V[Vendor]
GRN[GoodsReceipt] -- RECEIVED_AGAINST --> PO
INV[Invoice] -- BILLS --> PO
INV -- ISSUED_BY --> V
PAY[Payment] -- "SETTLES {amount}" --> INV
BL[BankLine] -- CLEARS --> PAY
RET[BankLine] -- REVERSES --> BL
G2B[GstrLine] -- REPORTS --> INV
PAY -- PAID_TO --> BA[BankAccount]
V -- "HAS_ACCOUNT {since}" --> BA
E[Employee] -- HAS_ACCOUNT --> BA
E -- APPROVED --> PAY
E -- ENTERED --> BC[BankChange]
BC -- NEW_ACCOUNT --> BA
184 nodes and 265 relationships. The builder infers the links from flat CSV ledgers using the keys an accountant would use: PO number, bank reference (UTR), GSTIN plus invoice number. See cypher/link.cypher. A receipt counts against a PO only if the PO number it was keyed with exists, which is how scenario 1 arises.
Item descriptions on purchase orders and receipts also carry a small text vector (item_vec): hashed character trigrams, 64 numbers, computed in trailmark/graph.py with no model and no network. It is enough to see that stores' "MS angle brkt 50 x 50 mm" is the PO's "MS angle bracket 50x50" (similarity 0.80), while an identical description (1.00) on a receipt already received against another PO is ruled out by the graph.
- Mode: single file,
store/trailmark.rl. - Why this mode: one period's books as one file is a unit finance people already work with. You can attach it, archive it, or hand it to an auditor. The same file is opened by the embedded Python library (the app and agent tools), by Relate's own CLI, and by
relate servefor MCP and Bolt. Readers open itread_only, so an agent can explore the books but cannot change them. The one write path is a single guarded statement. - What the graph models: the accounts-payable document trail above, plus the people and bank accounts around the money.
Relate features this project leans on:
| Feature | Where |
|---|---|
| Embedded Python library, no server | trailmark/graph.py builds and opens the store in-process |
Single-file .rl store, read_only opens |
store/trailmark.rl; every read in the CLI and agent server |
| Uniqueness constraints, vector index | cypher/schema.cypher |
SEARCH … VECTOR INDEX … WHERE … SCORE AS inside an OPTIONAL CALL subquery, then graph filters |
check 1: vector search proposes, the graph disposes |
Quantified path patterns ((…)-[…]-(…)){1,3} |
check 3, check 6, the trail |
EXISTS {} subqueries, list comprehension, reduce, duration.inDays |
all checks |
| WebAssembly build in the browser | web/: the page rebuilds the graph in the tab and runs the same .cypher files |
| MCP | trailmark/mcp.py (domain tools) and relate serve --mcp stdio --read-only (raw Cypher), both in .mcp.json |
| Agent-friendly results | the agent's read_cypher caps rows at 100 with an explicit truncated flag; the engine's own error text comes back so the agent can fix its query |
You need Python 3.10 or newer and git. Tested on Windows, macOS and Linux (CI).
git clone https://github.com/Automationbot24x7/trailmark
cd trailmark
python -m venv .venvActivate the environment. On Windows:
.venv\Scripts\activateOn macOS or Linux:
source .venv/bin/activateThen:
pip install -r requirements.txt # just relate-db, Relate's Python package
python -m trailmark scan # every exception in the sample books
python -m trailmark explain INV-1042
python -m trailmark view # the graph in your browser, on http://127.0.0.1:8765/web/scan prints:
Trailmark accounts payable as of 2026-10-31 SAMPLE DATA - all names and numbers are invented
──────────────────────────────────────────────────────────────────────────────
26 invoices 16 reconciled 4 matched, not yet due 6 exceptions ₹12,89,516 at risk
──────────────────────────────────────────────────────────────────────────────
● INV-1037 Large payment to a just-changed bank account ₹8,90,000
Paid to an employee's account
● INV-1036 Payment came back from the bank ₹1,95,600
Marked paid, ₹1,95,600 came back
● INV-1040 Same invoice paid twice ₹56,640
Duplicate of INV-1039, both paid
● INV-1038 Billed more than was received ₹4,956
Billed 1,000, received 900
● INV-1042 Invoice has no goods receipt ₹99,120
No goods receipt for PO-7713
● INV-1041 Tax credit claimed, supplier never filed ₹43,200
GST credit ₹43,200 at risk
Fix the one break the graph can repair, then put the books back:
python -m trailmark link GRN-5520 PO-7713 --note "PO digits swapped at stores" # INV-1042 is now matched
python -m trailmark build # rebuild store/trailmark.rl from the CSVsOther commands: python -m trailmark cypher "MATCH (v:Vendor) RETURN v.name" (read-only query), python -m trailmark export (refresh the browser copy), python -m unittest -v (eight end-to-end tests).
Your own ledgers: replace the CSVs in data/sample/ with your own exports, keeping the column headers, then run python -m trailmark build. Each file's columns are listed in its header row; data/generate_sample.py shows how the sample was made.
The store is a plain Relate database. With the Relate CLI installed:
relate --read-only -d store/trailmark.rl "MATCH path = SHORTEST 1 (e:Employee {id: 'E-06'})-[*]-(v:Vendor {id: 'V-108'}) RETURN [n IN nodes(path) | n.id] AS hops"That returns ["E-06","BA-8865","V-108"]: the AP clerk's salary account is the vendor's new bank account.
python -m trailmark mcp is an MCP server on stdio with five tools:
| Tool | What it does |
|---|---|
scan_exceptions |
every finding, with plain-English detail, amount at risk, evidence nodes and suggested fix |
explain_invoice |
one invoice's status, findings and trail (nodes with one-line summaries, relationships) |
link_receipt |
the one write: links an unlinked receipt to a same-vendor PO, recording linked_by, note and was_keyed_as |
read_cypher |
read-only Cypher, at most 100 rows plus a truncated flag |
get_schema |
labels, relationship types and what they mean in accounts-payable terms |
A real link_receipt call (run on a copy of the store) and what came back:
{"name": "link_receipt",
"arguments": {"grn_id": "GRN-5520", "po_id": "PO-7713",
"note": "Stores keyed PO-7731; same vendor, item and quantity as PO-7713"}}{
"ok": true,
"grn": "GRN-5520",
"po": "PO-7713",
"was_keyed_as": "PO-7731",
"linked_by": "agent (mcp)",
"invoices_now": [{"invoice": "INV-1042", "status": "matched", "remaining_findings": []}],
"undo": "python -m trailmark build (rebuilds the store from the sample CSVs)"
}In the browser the same fix is one button, and the trail turns green:
.mcp.json registers it (run your agent from the repo folder with the virtual environment active), alongside Relate's own relate serve --mcp stdio --read-only for raw access. AGENTS.md has the instructions and the questions used in the demo. Running relate skill install also teaches coding agents Relate's Cypher dialect.
Check 6 asks: which of our own people are within three hops of this payment, and how? In Cypher, that is one pattern over a list of relationship types:
MATCH path = (p:Payment {id: 'PAY-3410'})
((a)-[:PAID_TO|HAS_ACCOUNT|NEW_ACCOUNT|ENTERED|APPROVED]-(b)){1,3}
(e:Employee)
RETURN e.name, [r IN relationships(path) | type(r)] AS routeIn SQL, every route is its own join, and every new kind of link is another UNION arm:
SELECT e.name, 'approved the payment' FROM payments p JOIN employees e ON e.id = p.approved_by WHERE p.id = 'PAY-3410'
UNION ALL
SELECT e.name, 'owns the receiving account' FROM payments p JOIN employee_accounts ea ON ea.account_id = p.account_id
JOIN employees e ON e.id = ea.employee_id WHERE p.id = 'PAY-3410'
UNION ALL
SELECT e.name, 'entered the new account' FROM payments p JOIN bank_changes bc ON bc.new_account_id = p.account_id
JOIN employees e ON e.id = bc.entered_by WHERE p.id = 'PAY-3410'
UNION ALL
SELECT e.name, 'approved the bank change' FROM payments p JOIN bank_changes bc ON bc.new_account_id = p.account_id
JOIN employees e ON e.id = bc.approved_by WHERE p.id = 'PAY-3410';The Cypher returns all of these, plus a fifth route nobody wrote a join for: from the payment to the clerk who approved it, to the bank change that clerk entered, to the AP lead who approved that change. The same holds for the trail itself: cypher/trail.cypher is one 0-3 hop pattern that never walks through another invoice or bank account, so it pulls exactly one invoice's documents, however many payments, debits and returns there are.
| Path | What |
|---|---|
store/trailmark.rl |
the persistent Relate store (single file, about 300 KB). Inspect it with relate info -d store/trailmark.rl |
data/sample/*.csv |
the 13 sample ledgers it is built from (python data/generate_sample.py regenerates them) |
cypher/ |
schema, linking rules, the six checks, the trail query and the one write, all as plain .cypher files |
web/data/graph.json |
an export of the store for the browser. The WebAssembly build runs in memory and cannot open a .rl file, so the page rebuilds the same graph from this export |
trailmark/ Python package: graph.py (build/open), checks.py, render.py, mcp.py, export.py, view.py, __main__.py (CLI)
cypher/ every query the app runs, shared by the CLI, the agent server and the browser
web/ the browser view (plain HTML/CSS/JS) and the vendored Relate WebAssembly engine
data/ sample ledgers and their generator
store/ the Relate store
tests/ end-to-end tests (standard library only)
Watch on YouTube (1:36): one continuous take. It opens on Break the books (a receipt link is cut, the checks catch it, the fix is linked and the books restored), then INV-1042 and INV-1037 in the app, the command line, an AI agent fixing INV-1042 over MCP, and Relate's own CLI reading the fix from store/trailmark.rl, and the test that cuts every eligible receipt link. The terminal output is real, recorded and replayed. The video is made by video/: stage.html is the take, record.mjs records it with Chrome's screencast, and build.py assembles it with ffmpeg.
- Relate by Neo4j (Apache-2.0):
relate-dbfrom PyPI, and the unmodified@relate/relate-wasm1.0.1 package vendored inweb/vendor/relate-wasm/. - Fonts: Inter Tight and JetBrains Mono from Google Fonts.
- The paper-cut illustration (README hero, link preview, loading screen) was made with an AI image model; prompt in
docs/brand/art-prompts.md. Screenshots and diagrams are rendered from the app and from code. - Everything else was written for this hackathon, with help from an AI coding assistant (described in the Devpost submission).
MIT.




