Grounding guardrails for agentic RAG - deterministic claim verification
Project description
groundrails
Grounding guardrails for agentic RAG - deterministic, torch-free claim verification.
groundrails checks whether a claim is supported by source text and flags hallucinations and contradictions, with no LLM in the loop. It runs on CPU, returns a structured verdict per claim, and is the library extracted from the lexical-grounding research line (Rounds 1-12).
Why
Agentic RAG can assert things its sources never said. The usual fix - a second LLM grading each answer - is non-deterministic, costs a model call per claim, and gives no auditable reason for its verdict. groundrails is the deterministic gate that runs before output reaches the user.
- No LLM in the loop - frozen logistic weights over lexical features → same input gives the same verdict on every run
- Cheap - CPU-only, torch-free core; milliseconds per claim, no GPU, no API call
- Auditable - every verdict carries per-layer scores and the exact numeric or entity mismatch that triggered a flag
- Cross-lingual offline - claim-vs-evidence language gap is bridged by an on-device MT bridge, no translation API
- Research-backed - distilled from the lexical-grounding experiments (Rounds 1-12); see Documentation
What it does
- Claim grounding - locate a claim in source text across three lexical layers (regex exact, Levenshtein fuzzy, BM25 token-recall) and return a verdict with per-layer scores
- Hallucination and contradiction detection - numeric mismatch (
512vs1000), named-entity mismatch (H100vsA100), and unsupported-claim flags - Cross-lingual grounding - a claim in one language against evidence in another, via a torch-free MT bridge (argos / CTranslate2) and a SaT sentence segmenter (OpenVINO INT8)
- Self-consistency - intra-document divergence check (same entity or number category, different values)
- Frozen-weight verdict - a logistic manifold over 18 features at the
hightier; deterministic, no per-call sampling - Optional semantic layer - embedding retrieval + NLI entailment behind the
[semantic]extra; off by default, keeps the core torch-free
Install
pip install groundrails # core grounder (torch-free)
pip install "groundrails[semantic]" # add the optional embedding + NLI layer
CLI
The groundrails command verifies claims against source text read as plain UTF-8.
# put the evidence in a file, then ground a claim against it
echo "The Eiffel Tower is located in Paris, France." > doc.txt
groundrails ground --claim "The Eiffel Tower is in Paris." --source doc.txt
# → exit 0 (grounded); prints the match type, per-layer scores, and matched text
groundrails ground --claim "<claim>" --source doc.txt- ground one claim; exit 0 if grounded, 1 if notgroundrails ground --manifest claims.json --source doc.txt [--json]- batch over many claimsgroundrails extract-claims --document doc.md- heuristic sentence-to-claim extractorgroundrails check-consistency --document doc.md- intra-document divergence reportgroundrails config- print the resolved config + calibration blockgroundrails setup- first-run semantic model/cache config
--semantic adds the optional embedding + NLI bundle to ground.
Python API
from groundrails import ground, ground_batch
m = ground(
"The Eiffel Tower is in Paris.",
["The Eiffel Tower is located in Paris, France."],
)
print(m.match_type, m.combined_score, m.verdict_probability)
ground_batch(claims, sources, ...) runs many claims against the same sources and returns a list of verdicts.
Language support
Cross-lingual grounding needs an argos <lang>→en model for the claim's language. English is native and needs no bridge. Nine non-English languages have models installed.
| Language | Code | Grounding |
|---|---|---|
| English | en |
✓ |
| Danish | da |
✓ |
| German | de |
✓ |
| Spanish | es |
✓ |
| French | fr |
✓ |
| Italian | it |
✓ |
| Norwegian Bokmål | nb |
✓ |
| Dutch | nl |
✓ |
| Portuguese | pt |
✓ |
| Swedish | sv |
✓ |
| Norwegian Nynorsk | nn |
✗ |
| Latin | la |
✗ |
| Yoruba | yo |
✗ |
| Estonian | et |
✗ |
| Esperanto | eo |
✗ |
| Tsonga | ts |
✗ |
| Tagalog | tl |
✗ |
| Catalan | ca |
✗ |
| Czech | cs |
✗ |
| Hungarian | hu |
✗ |
| Tswana | tn |
✗ |
✓ grounded - English native, others via the argos MT bridge · ✗ no installed argos model → UnsupportedLanguageError (any language not listed defaults to ✗)
- Supported - full cross-lingual grounding: the claim is translated to English, then recall-matched against the evidence
- Unsupported - a non-English claim with no installed model →
ground()raisesUnsupportedLanguageError; the claim is hard-blocked, not scored, so unsupported languages cannot pollute metrics (batch callers wrap per claim) - Add a language -
argospm install translate-<code>_eninstalls the model; the bridge picks it up automatically - Region tags - the detector strips the region before lookup (
it-IT→it,nb-NO→nb)
Documentation
The docs/ tree carries the concept, the calibration method, and the full research history behind the shipped weights.
- Concept -
docs/grounding_concept.md- what grounding means here and how a verdict is assembled - Calibration -
docs/grounding_calibration.md- how the frozen weights and thresholds were fit - Experiments log -
docs/experiments/lexical-grounding-experiments.md- Rounds 1-12, what moved the metrics and what did not - State of the art -
docs/experiments/lexical-grounding-sota.md- how the deterministic cascade compares to published grounding methods - Positional analysis -
docs/lost_in_the_middle_grounding_analysis.md- lost-in-the-middle behaviour over long evidence
Project layout
src/groundrails/- the grounder (grounding,lexical,lexical_mt,entity_check,consistency,calibration,chunking,extract,sat/,config+ the shippedconfig_document_processing.yaml)experiments/grounding/- research harness (Rounds 1-12)notebooks/- calibration, SaT / OpenVINO conversion, manifold retrainingtests/- grounder tests + the exact-equivalence goldendata/,models/,references/- datasets, OpenVINO IR, papers (large/private content gitignored)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file groundrails-1.0.29.tar.gz.
File metadata
- Download URL: groundrails-1.0.29.tar.gz
- Upload date:
- Size: 109.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bfac8da2a02d42571b7367d645a4e6c297a75f78bd1213fb1d4d7920c0d36189
|
|
| MD5 |
7a879c6c8dbe96233482fe2d7638ba12
|
|
| BLAKE2b-256 |
9a4842529bc12c39fae83c513fc4c561c1d7aa8cb10705c79cac8e3c757be403
|
File details
Details for the file groundrails-1.0.29-py3-none-any.whl.
File metadata
- Download URL: groundrails-1.0.29-py3-none-any.whl
- Upload date:
- Size: 90.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1a93f1ebcf63b8814ffc98d4eb645a331f6a95c7996e3c199913efda2e9fa337
|
|
| MD5 |
d3721fa5d70496ff1c59b614af671bc1
|
|
| BLAKE2b-256 |
9d2e306b3de808ae661b763ebe17191c2fe84c6f5b92e137d6839c8c5504f69c
|