nx_cite_lib.nx
buildroot/runtime/nx_cite_lib.nx
about
nx_cite_lib.nx -- F993 CITE-OR-ABSTAIN: deterministic citation verification, the legal flagship.
THE 2026 WALL (measured, not rhetorical): independent benchmarks show ~24% of graded legal answers
cite or misapply law that does NOT support the claim, and every model tested fabricated at least one
citation. The sovereign answer is not a better-behaved chatbot -- it is a VERIFIER that structurally
cannot pass a citation whose quoted text is not BYTE-PRESENT in the cited source. No LLM sits in the
trust path: a citation is verified by exact substring containment against a stored, content-addressed
source, so a fabricated or subtly-altered quote is caught by construction.
FAIL-CLOSED, three honest outcomes:
CITED (1) the quote is an exact span of a real source -> show the source
ABSTAIN_NO_SOURCE (-1) the cited source does not exist (the "made-up case" failure)
ABSTAIN_NO_SPAN (-2) the source exists but the quote is not in it (fabricated/altered/empty)
An empty quote is ABSTAIN, never CITED -- "the empty string is a substring of everything" is exactly
the hole a fabricator would drive through, so it is closed explicitly.
BYTE-EXACT is the honest floor. Normalization (whitespace collapse, case-fold, smart-quote unify) is
a DECLARED follow-on, not silently applied -- a verifier that quietly normalizes can be tricked into
accepting a materially altered quote, so the strict floor ships first and any loosening is opt-in.
SCALE ENVELOPE (declared): cite_verify is O(source-length) substring scan per call (Rabin-Karp/KMP is
the speed rung); source retrieval inherits the seg-store read cost (see the finance-spine scale note).
DRY: composes nx_matter_lib (reg_put/reg_get/mt_field/canon_encode). license_tier: ORIGINAL LIB.
dependencies 1 imports · 3 importers
imports: nx_matter_lib.nx
imported by: nx_citator_lib.nxnx_cite_gate.nxnx_cite_redline_gate.nx
structs
| none |
consts
| 27 | const CITE_CITED: i64 = 1 |
| 28 | const CITE_ABSTAIN_NO_SOURCE: i64 = 0 - 1 |
| 29 | const CITE_ABSTAIN_NO_SPAN: i64 = 0 - 2 |
| 30 | const CITE_SRC_CAP: i64 = 65536 // max stored source length (declared) |
functions
| 32 | func cite_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } |
| 36 | func cite_contains(hay: *u8, hl: i64, needle: *u8, nl: i64) -> i64 called by 1: cite_verify |
| 52 | func cite_source_put(prefix: *u8, source_id: *u8, text: *u8) -> i64 |
| 63 | func cite_source_text(prefix: *u8, source_id: *u8, out: *u8) -> i64 |
| 74 | func cite_verify(prefix: *u8, source_id: *u8, quoted: *u8) -> i64 |
| 86 | func cite_ok(prefix: *u8, source_id: *u8, quoted: *u8) -> i64 |
| 100 | func cite_scan_doc(prefix: *u8, doc: *u8, report: *u8) -> i64 |
| 155 | func cite_doc_clean(prefix: *u8, doc: *u8) -> i64 |