Skip to main content

Grounding guardrails for agentic RAG - deterministic claim verification

Project description

groundrails

CI PyPI version Total PyPI downloads Python 3.12 License: MIT Brought To You By KOLOMOLO Donate PayPal

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 (512 vs 1000), named-entity mismatch (H100 vs A100), 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 high tier; 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 not
  • groundrails ground --manifest claims.json --source doc.txt [--json] - batch over many claims
  • groundrails extract-claims --document doc.md - heuristic sentence-to-claim extractor
  • groundrails check-consistency --document doc.md - intra-document divergence report
  • groundrails config - print the resolved config + calibration block
  • groundrails 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() raises UnsupportedLanguageError; 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>_en installs the model; the bridge picks it up automatically
  • Region tags - the detector strips the region before lookup (it-ITit, nb-NOnb)

Documentation

The docs/ tree carries the concept, the calibration method, and the full research history behind the shipped weights.

Project layout

  • src/groundrails/ - the grounder (grounding, lexical, lexical_mt, entity_check, consistency, calibration, chunking, extract, sat/, config + the shipped config_document_processing.yaml)
  • experiments/grounding/ - research harness (Rounds 1-12)
  • notebooks/ - calibration, SaT / OpenVINO conversion, manifold retraining
  • tests/ - grounder tests + the exact-equivalence golden
  • data/, 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

groundrails-1.0.29.tar.gz (109.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

groundrails-1.0.29-py3-none-any.whl (90.4 kB view details)

Uploaded Python 3

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

Hashes for groundrails-1.0.29.tar.gz
Algorithm Hash digest
SHA256 bfac8da2a02d42571b7367d645a4e6c297a75f78bd1213fb1d4d7920c0d36189
MD5 7a879c6c8dbe96233482fe2d7638ba12
BLAKE2b-256 9a4842529bc12c39fae83c513fc4c561c1d7aa8cb10705c79cac8e3c757be403

See more details on using hashes here.

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

Hashes for groundrails-1.0.29-py3-none-any.whl
Algorithm Hash digest
SHA256 1a93f1ebcf63b8814ffc98d4eb645a331f6a95c7996e3c199913efda2e9fa337
MD5 d3721fa5d70496ff1c59b614af671bc1
BLAKE2b-256 9d2e306b3de808ae661b763ebe17191c2fe84c6f5b92e137d6839c8c5504f69c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page