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 each claim in an answer is backed by your source, and tells you exactly where the support is - or flags it as a hallucination or contradiction. No LLM in the loop, runs on CPU, same answer every time.

groundrails - deterministic claim grounding

Why

Agentic RAG can assert things its sources never said. The usual fix - a second LLM grading each claim - is slow, costs a model call per claim, is non-deterministic, and gives no reason for its verdict. groundrails is the deterministic gate that runs before the answer reaches the user: milliseconds per claim, no GPU, no API call, and an auditable pointer to the exact supporting passage.

Quickstart

pip install groundrails

# extract the claims from an answer, check each against the evidence
groundrails ground answer.md evidence.txt --json

[!IMPORTANT] groundrails grounds plain text only (UTF-8). Convert a PDF, DOCX, or scanned document to markdown or text first - with a separate document-processing tool - then ground the result.

You get back a grounding document: per claim, a verdict, a confidence score, and exactly where the support sits in the evidence - the quoted passage and its line / character offset. This is what an agent reads to cite a source or retract a claim:

{
  "summary": {"total": 12, "grounded": 9, "ungrounded": 3},
  "claims": [
    {
      "claim": "The tower was completed in 1889.",
      "claim_location": {"line": 5, "char_start": 120, "char_end": 152},
      "grounded": true,
      "score": 0.94,
      "support": {
        "source_path": "evidence.txt",
        "matched_text": "the Eiffel Tower was completed in 1889",
        "line_start": 12, "char_start": 210, "char_end": 248
      }
    }
  ]
}

Read it like this:

  • grounded - true if the evidence backs the claim, false if it is unsupported or contradicted
  • score - confidence in the verdict, 0 to 1
  • support - the exact passage that backs the claim, with its source, line, and character offset
  • contradiction - the conflicting value (a number or entity) when the claim disagrees with the source

Three ways to supply the claims; the rest of the positionals are always evidence:

groundrails ground answer.md evidence1.txt evidence2.txt          # claims extracted from a document
groundrails ground --claims claims.json evidence.txt              # a claims file
groundrails ground --claim "The tower is in Paris." evidence.txt  # inline (repeatable)

A claims.json is what extract-claims writes - a list of {claim, ...} objects (only claim is required; id and the location fields are optional). It can also be a plain list of strings, or a text file with one claim per line.

[
  {"id": "c01", "claim": "The Eiffel Tower is in Paris.", "line_number": 5, "char_start": 120, "char_end": 152},
  {"id": "c02", "claim": "It was completed in 1889.", "line_number": 5, "char_start": 153, "char_end": 178}
]

Drop --json for a readable line per claim; add --full-output for the per-scorer detail. From Python:

from groundrails import grounding_document

doc = grounding_document(
    ["The Eiffel Tower is in Paris."],
    [("evidence.txt", "The Eiffel Tower is located in Paris, France.")],
)

Cross-lingual claims and a deeper semantic check are opt-in: install groundrails[semantic-grounder] and add --semantic 1.

What you get

  • Where the support is - the quoted passage, source, line, and character offset for every grounded claim
  • Hallucination and contradiction flags - claims the source never made, and value conflicts like 512 vs 1000 or H100 vs A100
  • Cross-lingual checks - a claim in one language against evidence in another, fully on-device
  • A deterministic answer with a reason - frozen weights, same verdict every run, an auditable score behind each decision

Languages

English is native. Nine more work through an on-device translation bridge: Danish, German, Spanish, French, Italian, Norwegian Bokmål, Dutch, Portuguese, Swedish. A claim in any other language is blocked rather than silently mis-scored; add one with argospm install translate-<code>_en.

How it works & how it performs

Two layers: a fast deterministic lexical grounder, and an optional model-based cascade (--semantic) that escalates only the claims the fast path is unsure about. On a verified gold set the lexical grounder reaches macro-F1 0.76, and the semantic switch lifts it to 0.82. The full design, benchmarks, and comparison to published methods live in the two SOTA write-ups:

Documentation

License

MIT

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.31.tar.gz (127.6 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.31-py3-none-any.whl (103.2 kB view details)

Uploaded Python 3

File details

Details for the file groundrails-1.0.31.tar.gz.

File metadata

  • Download URL: groundrails-1.0.31.tar.gz
  • Upload date:
  • Size: 127.6 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.31.tar.gz
Algorithm Hash digest
SHA256 2b8043dbd15ae5c23a76b192b13ec1c574158a9fb28b4d892fa395ec0f5e6286
MD5 6de58000d33a5272acc6374d321584f6
BLAKE2b-256 a0e40586566a16296e84878a8a2fe555728e6ce94f30de9a9b3c71fb2243d6aa

See more details on using hashes here.

File details

Details for the file groundrails-1.0.31-py3-none-any.whl.

File metadata

  • Download URL: groundrails-1.0.31-py3-none-any.whl
  • Upload date:
  • Size: 103.2 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.31-py3-none-any.whl
Algorithm Hash digest
SHA256 5914bdfaeccd554c28f3b76c6d9015e034d1a8e917895eb02ac777b284ca7ced
MD5 e223a24e276dfa4c61b507f05260a68a
BLAKE2b-256 8f668b81f09d7d75cc77d0a8809c17dabe9f332470be6141e32c9d1a0f3d0cd4

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