Around 1140, a teacher of law in Bologna named Gratian set out to put the law of the Church in order. A thousand years of canons, letters and sayings, each written for its own occasion, disagreed with one another. Where two texts conflicted, Gratian set them side by side and wrote between them why, rightly read, they need not. He called his book A Harmony of Discordant Canons.
Our version of the problem is shorter in time and larger in volume. Change one definition in a large corpus of normative documents, a thousand pages or more, and the new definition is the easy part. The hard part is everything else: the forty sentences that use the term, the six that only made sense under the old meaning, and the one in an annex that nobody has opened for a year. Legislative drafters call this work consequential amendments, and it is still done in Gratian’s way: by a careful reader with a good memory. That tool does not scale to a thousand pages, and it retires.
What follows is a design for doing this work with machines, without handing them the judgement. It is a design, not a report from production: the foundation is ordinary practice for documents kept in Git, and everything involving a language model is a proposal. The shape fits any such corpus: a regulation with its technical standards, an institution’s policy handbook, a family of contracts, or the specification of a large system.
I. Two problems
The first problem is inconsistency, and it comes in two kinds.
- Hard inconsistencies can be checked exactly. The same thing carries different identifiers in different places. A cross-reference points to a section that no longer exists. A defined term is spelt two ways.
- Semantic inconsistencies cannot. Two passages say things that cannot both be true, without sharing a single word. One section now allows something; another, forty pages later, still requires a step before it.
The second problem is change propagation. When a definition changes, where else must the text change? Search and replace finds every use of a word. It does not find the sentences whose meaning has quietly shifted underneath them.
The hard kind is a job for code. The semantic kind, and propagation, is where a language model can help, if it is kept on a short lead.
II. Five principles
- Deterministic first. Everything code can check exactly (identifiers, references, the spelling of defined terms) is checked by code: exact, cheap, and allowed to block a merge.
- The model only for what code cannot do, and advisory, never blocking. A check that cries wolf is switched off within a month. False positives kill adoption faster than any missed finding.
- The human decides. The model proposes a finding with a reason. An author accepts it or dismisses it, with a reason of their own.
- On premises. No text leaves the institution. For many normative documents this is not a preference but a condition, and open-weight models make it possible.
- Everything versioned and traceable: the text, the prompts, the model version, every finding and every decision.
The order matters. The first principle means the model never spends effort on what a regular expression can do. The third means that its mistakes cost a click, not a wrong rule.
III. The foundation: text a machine can address
None of this works on a folder of word-processor files. It needs four things, all of them ordinary for documents kept as Markdown in Git:
- The text as Markdown in Git, one file per chapter or section.
- Stable identifiers on every heading, so that a finding points at a section, not at a line number that moves with the next edit.
- The glossary and the register of identifiers as structured data, for example in YAML: one source for every defined term and every identifier, which the text refers to.
- Changes only through merge requests, reviewed and approved.
The last point matters most for what follows. A merge request is the moment when a change is small, named and waiting for a reviewer. That is exactly when a consistency check is cheapest to run and most useful to read.
IV. The architecture at a glance
%%{init: {"layout": "elk", "fontFamily": "Noto Sans, Arial, sans-serif", "theme": "base", "themeVariables": {"fontFamily": "Noto Sans, Arial, sans-serif", "fontSize": "14px", "primaryColor": "#E8F1FB", "primaryBorderColor": "#3B78C4", "primaryTextColor": "#1F2933", "lineColor": "#5F6B7A", "secondaryColor": "#FFF4E6", "tertiaryColor": "#F5F7FA"}}}%%
flowchart TB
subgraph GL["GitLab"]
direction LR
MR["Merge request<br/>opened or updated"]
LINT["Stage 1: linters<br/>blocking"]
MAIN["Merge to main"]
end
subgraph PF["AI platform, on premises"]
direction LR
IDX["Index job<br/>split, hash, embed"]
CHK["Check service<br/>asynchronous jobs"]
EMB["Embedding and reranker<br/>CPU"]
LLM["Language model<br/>open weights, GPU"]
VDB[("Vector store<br/>as of main")]
OBJ[("Object storage<br/>findings as JSON")]
VIEW["Report viewer"]
end
AUT["Author and reviewer"]
MR --> LINT
LINT -->|"changed sections"| CHK
CHK -->|"embed new version"| EMB
CHK -->|"nearest neighbours"| VDB
CHK -->|"pairs to judge"| LLM
CHK -->|"findings"| OBJ
CHK -->|"report"| MR
OBJ --> VIEW
AUT -->|"accept or dismiss,<br/>with a reason"| MR
MAIN --> IDX
IDX --> EMB
IDX -->|"update vectors"| VDB
classDef git fill:#FFF4E6,stroke:#E8A23B,color:#1F2933
classDef svc fill:#E8F1FB,stroke:#3B78C4,color:#1F2933
classDef gpu fill:#EDE7F6,stroke:#7E57C2,color:#1F2933
classDef store fill:#E6F4EA,stroke:#2E8B57,color:#1F2933
classDef human fill:#FCE8F0,stroke:#C2185B,color:#1F2933
class MR,LINT,MAIN git
class IDX,CHK,EMB,VIEW svc
class LLM gpu
class VDB,OBJ store
class AUT human
style GL fill:#FFFBF5,stroke:#E8A23B
style PF fill:#F7FAFE,stroke:#3B78C4
Orange is GitLab, blue the services on ordinary CPUs, violet the one workload that needs GPUs, green the stores, pink the people. There are two loops. Every merge to main keeps an index of the whole text up to date. Every merge request is checked against that index.
The model does not know the text. This is the point most often misunderstood. A language model sees only what is in its prompt. The memory of the corpus is the vector index, built by a small embedding model that is separate from the language model: each section of the text becomes a list of numbers, and sections about similar things end up close to each other.
The index is built along the headings. Each section keeps its identifier and its full heading path (document, chapter, section), not just its last heading, and is stored with its file, its commit and a hash of its text. On every merge to main, only the sections whose hash has changed are embedded again, and removed sections are deleted. The index always reflects main, which is the baseline every merge request is checked against.
The volume is smaller than it sounds. A body of a few thousand pages is perhaps ten thousand sections; at about a thousand numbers per section, that is a few tens of megabytes. Embedding all of it takes minutes. The hard parts are cutting the sections well and keeping the index in step with the text, not the size.
V. A merge request, end to end
GitLab runs a merge request pipeline as soon as a merge request is opened or updated, before anyone approves it.
%%{init: {"fontFamily": "Noto Sans, Arial, sans-serif", "theme": "base", "themeVariables": {"fontFamily": "Noto Sans, Arial, sans-serif", "fontSize": "14px", "actorBkg": "#E8F1FB", "actorBorder": "#3B78C4", "actorLineColor": "#9AA5B1", "actorTextColor": "#1F2933", "noteBkgColor": "#FFFDE7", "noteBorderColor": "#C9A400", "signalColor": "#3B4A5A", "signalTextColor": "#1F2933", "labelBoxBkgColor": "#E8F1FB", "labelBoxBorderColor": "#3B78C4", "loopTextColor": "#1F2933", "activationBkgColor": "#E8F1FB", "sequenceNumberColor": "#FFFFFF"}, "sequence": {"actorMargin": 30, "messageFontSize": 16, "actorFontSize": 16, "noteFontSize": 15, "boxMargin": 8}}}%%
sequenceDiagram
autonumber
actor A as Author
participant G as GitLab
participant C as Check service
participant E as Embedding
participant V as Vector store
participant L as Language model
participant O as Object store
A->>G: Opens or updates a merge request
G->>G: Stage 1, linters
alt a reference does not resolve
G-->>A: Fails, merge blocked
else linters pass
G->>C: Changed sections, OIDC token
C-->>G: Accepted, job ID
Note over C,V: Stage 2, the impact set
C->>C: References, uses of terms
C->>E: Embed the changed sections
E-->>C: Vectors
C->>V: Neighbours, hybrid search
V-->>C: Candidates, reranked
Note over C,L: Stage 3, pair by pair
loop each pair not yet in the cache
C->>L: The pair, and a JSON schema
L-->>C: A finding, or none
end
C->>O: Findings, with provenance
G->>C: Polls the job
C-->>G: Report
G-->>A: Findings in the merge request
A->>G: Accept and fix, or dismiss
end
Stage 1: deterministic linters, blocking. Every identifier the text refers to exists in the register. Every cross-reference resolves. Every defined term is spelt as defined, and no capitalised term is left undefined. The structure and the metadata of each file are valid. If any of this fails, the merge is blocked, and the language model is never asked.
Stage 2: the impact set. A diff against the merge base shows which sections changed. For each of them, the check service collects the passages the change can affect:
- Explicit references, found deterministically: the sections that cite the changed identifier or use the changed term, from a reference graph built from the identifiers.
- Semantic neighbours, found with embeddings: the new version of the changed section is embedded with the same model as the index, and the ten to twenty nearest sections are retrieved, leaving out the old version of the same section.
- Hybrid search and reranking: a keyword search (BM25) runs alongside, so that exact terms are not missed, and a reranker scores the candidates again. Embeddings find passages about the same topic. They do not find contradictions, and a contradiction can be phrased very differently from what it contradicts.
- Merge and deduplicate the three lists.
Stage 3: the model, pair by pair. For each pair, the changed passage and one candidate, the service asks one narrow question: does passage B contradict passage A, or does B need to change because of A? Answer in this JSON schema. For a change of definition, the new definition is the reference: is each passage that uses the term still consistent with it?
- Temperature zero, a pinned model version, and the prompt kept in Git like code.
- Structured output: the serving software forces the answer into the schema, and the service validates it again.
- A cache, keyed by the hash of each passage, the model version and the prompt version. An unchanged pair is never checked twice, so a second run after a small fix costs almost nothing.
The pairwise question is deliberately small. A model asked to “check these rules for consistency” will produce confident prose about whatever it noticed. A model asked whether two given passages fit together, with a schema to answer in, produces something that can be counted, cached and checked.
Stage 4: the report. The findings come back as JSON, and the pipeline hands them to GitLab in its code quality report format, so they appear in the merge request itself, where the author is already working. The full findings go to object storage, with a simple viewer for the larger picture.
Stage 5: the human decides. Each finding is accepted, and the author fixes the text, or dismissed with a reason. Each finding has a fingerprint, so a dismissed finding does not come back on the next run. Every decision is recorded, and becomes labelled data for measuring the model.
VI. When a definition changes
Change propagation is the same pipeline, pointed at the glossary.
%%{init: {"layout": "elk", "fontFamily": "Noto Sans, Arial, sans-serif", "theme": "base", "themeVariables": {"fontFamily": "Noto Sans, Arial, sans-serif", "fontSize": "14px", "primaryColor": "#E8F1FB", "primaryBorderColor": "#3B78C4", "primaryTextColor": "#1F2933", "lineColor": "#5F6B7A", "secondaryColor": "#FFF4E6", "tertiaryColor": "#F5F7FA"}}}%%
flowchart TD
D["1. The author changes<br/>a definition"] --> X["2. A linter finds<br/>every exact use"]
X --> R["Search and replace<br/>for a change of spelling"]
X --> N["3. The uses, plus their<br/>semantic neighbours"]
N --> L["The model checks<br/>each passage against<br/>the new definition"]
L --> FL["Flagged sentences,<br/>each with a reason<br/>and a suggestion"]
FL --> W["4. The author rewords them"]
R --> MR
W --> MR["One merge request:<br/>the definition<br/>and all its consequences"]
MR --> REV(["The reviewer sees<br/>the whole change"])
classDef git fill:#FFF4E6,stroke:#E8A23B,color:#1F2933
classDef svc fill:#E8F1FB,stroke:#3B78C4,color:#1F2933
classDef gpu fill:#EDE7F6,stroke:#7E57C2,color:#1F2933
classDef human fill:#FCE8F0,stroke:#C2185B,color:#1F2933
class D,W human
class X,R,N,FL svc
class L gpu
class MR,REV git
- The author changes the definition in the glossary file.
- A linter finds every exact use of the term. If only the spelling changed, search and replace does the rest.
- The model checks every passage that uses the term, and its semantic neighbours, against the new definition, and flags the sentences whose meaning no longer fits, each with a reason and, if it can, a suggested rewording.
- The author rewrites those sentences in the same merge request.
The merge request then holds the definition and all its consequences together. That is what a reviewer needs to see, and what is almost impossible to assemble by hand: today, the consequences of a definition change usually arrive weeks later, one surprised reader at a time.
VII. The first full check
A merge request checks one change against the rest. The first time, the whole text has to be checked against itself, and that is a different job. The corpus does not fit into one prompt, and comparing every section with every other grows with the square of their number.
So the first check runs as a batch job, overnight, at low priority, in two passes:
- Term by term: for each defined term, every passage that uses it, checked against the definition.
- Topic by topic: the sections clustered by their embeddings, and pairs checked within each cluster.
Expect a large first backlog. Sort it by severity, fix the major findings first, and work the rest down over weeks, not in one sitting.
VIII. A finding is data
{
"finding_id": "f-3a91c2",
"fingerprint": "sha256:9e1b...",
"type": "semantic_contradiction",
"severity": "major",
"changed": { "section_id": "R-4.2.3", "file": "chapters/04.md", "excerpt": "..." },
"affected": { "section_id": "R-7.1.1", "file": "chapters/07.md", "excerpt": "..." },
"explanation": "4.2.3 now allows X; 7.1.1 still requires Y before X.",
"suggestion": "Reword 7.1.1 to ...",
"confidence": 0.82,
"provenance": {
"model": "open-weight-llm", "model_version": "2026-09",
"prompt_version": "consistency-v4", "index_commit": "a1b2c3d"
},
"decision": null
}
A finding is not a chat message. It has an identity, a place in the text on both sides, a reason, and a record of where it came from. The provenance block answers, months later, the question an auditor will ask: which model, which prompt and which version of the text produced this finding? And the empty decision field is waiting for the only opinion that counts.
IX. A platform, not a project
The consistency check is one customer. The platform is what makes it, and the next ten like it, cheap and safe.
| Platform service | Role in this use case | Reused by |
|---|---|---|
| Model serving (for example vLLM, with the language, embedding and reranking models) | Generation and embeddings, on GPUs, behind one API | every application of language models in the institution |
| Vector store (for example pgvector) | The index of the corpus | every retrieval application |
| Check service | Builds the impact set, calls the model, validates the answers | any body of text with rules: policies, regulations, contracts, specifications |
| Pipeline component (a reusable GitLab CI component) | The stages of the merge request pipeline | any team with documents in Git |
| Object storage and viewer | The reports | other jobs that produce reports |
Self-service. A team that wants consistency checks for its own documents should not need the platform team. It brings a Git repository with Markdown and stable identifiers, a small configuration file (which paths, which glossary, which rules, which severity blocks a merge) and one line in its .gitlab-ci.yml that includes the shared component. It gets its own index, the pipeline and the reports. The principle: make the compliant path the fastest path, and teams take it of their own accord.
Separation between teams. One index per corpus. Access to an index and its reports follows the access rights of the repository. The classification of each section travels with it into the index and is filtered at retrieval time. Quotas per team, so that one large backlog run cannot starve everyone else’s merge requests.
Running it. The model runs on a pool of GPU nodes reserved for it; everything else runs on ordinary CPUs. A check is an asynchronous job: the service answers at once with a job number, a queue holds the work, and workers scale with the length of the queue rather than with CPU load. Model weights come from an internal registry, pinned by version and checksum, never downloaded from the internet at start-up. The overnight batch and the merge requests have separate queues, and the merge requests win.
Security. No text leaves the institution, and network rules let only the check service reach the model. The pipeline authenticates to the service with GitLab’s short-lived OIDC token for the job, so there are no stored secrets. And the text is untrusted input: a normative document can contain a sentence that reads like an instruction to a model. So the model gets no tools and no actions. It can produce a finding, in a schema checked by code, and nothing else; it never changes a file. Logs and reports inherit the classification of the text they quote, and the model’s licence and origin are reviewed before it is used.
Observability. The usual signals for each service (latency, traffic, errors, saturation), plus those of a language model: time to the first token, tokens per second, queue length, GPU use, cache hits. One trace per check, with a span per stage, so that a slow pipeline shows where its time goes. And one number that is not technical at all: the share of findings that people accept, a running estimate of precision. If it drops after a change of model or prompt, that is an incident, like any other.
Reliability. The model’s stage is advisory, so if the model is down, that stage fails softly and the merge request is not blocked; the deterministic stage still blocks. Every call has a timeout and a retry, and every job has a key made of the merge request, the commit and the stage, so a retried pipeline does not create duplicate work.
The model’s own lifecycle. The model version and the prompt live in Git, and a change to either goes through a merge request like any other code. Before a new model or prompt goes live, it runs against the evaluation set in the pipeline, and it must not lose precision or recall beyond an agreed margin. Under the EU AI Act, an internal assistant whose every output is decided by a person is likely a low-risk use; your own AI governance function should confirm it.
X. Knowing whether it works
- A golden set: inconsistencies planted on purpose (an identifier renamed in one place, a definition changed without its uses), plus real cases found in the past.
- Human decisions as labels: every accepted and every dismissed finding.
- Precision first, then recall: how many findings are real, and how many of the planted cases are found. And the time an author spends per finding, because a correct finding that takes ten minutes to understand is still a cost.
- A regression test in the pipeline for every change of model, prompt or the way the text is cut into sections.
XI. Rolling it out
- The deterministic linters first. Immediate value, no risk from a model, and the register of identifiers that every later stage needs.
- The model on definition changes only, in shadow mode: findings are logged but not shown, and compared with what the reviewers found by themselves.
- Advisory findings on all merge requests, once precision is good enough that people read them.
- The full check of the corpus, and its backlog worked down over weeks.
- Open it to other teams as a self-service component of the platform.
Each step earns the next. Shadow mode in particular costs little and settles the question that matters most before anyone has to trust the model: on our text, with our definitions, how often is it right?
XII. What it will not do
- False positives erode trust quickly. Hence precision first, advisory only, and dismissals remembered.
- Embeddings find topics, not contradictions. Hybrid search and a reranker reduce what is missed, but recall will never be complete. The check supports review; it does not replace it.
- The cut decides the quality. Sections cut badly give bad neighbours, and bad neighbours give bad findings.
- GPU capacity is shared and scarce, hence queues, priorities and quotas.
- Over-trust is the quiet risk. A clean report does not mean a consistent corpus. It means the checks found nothing.
XIII. Memory and judgement
Every institution that keeps rules depends on people who remember: the drafter who knows that one article leans on a definition in an annex, the reviewer who has read the whole text twice. Those people move on, retire, or are simply too busy to read a thousand pages for a two-line change.
The design above does not replace them. It gives the remembering to an index and a patient reader that never tires of comparing two paragraphs, and it keeps the judging where it belongs. The model proposes; the author decides; and the record of both stays in the history, where the next person can find it.
Tools, briefly
- Embeddings: sentence-transformers or FastEmbed in Python, served with Text Embeddings Inference or vLLM. Multilingual open-weight models such as bge-m3 or multilingual-e5 (the latter expects the prefixes
query:andpassage:). Choose on real pairs from your own text, not only on a public benchmark. - Rerankers: for example bge-reranker-v2-m3.
- Vector stores: pgvector, Qdrant or Milvus; FAISS or Chroma for prototypes.
- Serving the language model: vLLM, with structured output against a JSON schema, and an open-weight model that your institution’s rules allow.