Skip to main content

🛡️ RAGGround

PyPI version Python versions License Test Suite Precision

RAGGround is a lightweight, sub-millisecond hallucination guardrail, citation verifier, and RAG evaluation engine.

It verifies whether an LLM-generated answer is strictly grounded in the retrieved context documents, automatically detects extrinsic fabrications and numerical contradictions, and injects clean inline citations ([1], [2]).


⚡ Key Highlights

  • 🚀 Sub-Millisecond Execution: Tier 1 deterministic alignment evaluates in < 0.3 ms on standard CPU.
  • 🧠 Neural NLI Verification: Backed by quantized cross-encoder models for semantic entailment verification.
  • 🎯 100% Precision Hallucination Defense: Catches numerical errors, swapped entities, and unsupported claims with zero false approvals.
  • 📚 Automated Citation Injection: Injects inline citation tags ([1]), footnotes, or HTML hover tooltips into the LLM output.
  • 📊 Batch Dataset Evaluation: Benchmark entire RAG datasets and compute grounding accuracy, hallucination rate, and latency.

📦 Installation

pip install ragground

🚀 Quickstart

1. Basic Single-Query Verification

from ragground import RAGGround

# Initialize the guardrail
guard = RAGGround()

context = """
Tesla reported Q3 automotive revenue of $20.02 billion, representing an 8% increase 
year-over-year. Free cash flow for the quarter was $2.74 billion.
"""

answer = """
Tesla reported Q3 automotive revenue of $20.02 billion, up 8% YoY. 
Free cash flow reached $2.74 billion. 
The company also announced a new smartphone for $999.
"""

report = guard.verify(context=context, answer=answer)

print("Is Grounded:       ", report.is_grounded)          # False
print("Grounding Score:   ", f"{report.grounding_score*100:.1f}%")  # 66.7%
print("Verified Claims:   ", report.verified_count)        # 2
print("Hallucinations:    ", report.unsupported_count)     # 1

print("\nCited Answer:")
print(report.cited_answer)

Output:

Is Grounded:        False
Grounding Score:    66.7%
Verified Claims:    2
Hallucinations:     1

Cited Answer:
Tesla reported Q3 automotive revenue of $20.02 billion, up 8% YoY. [1] 
Free cash flow reached $2.74 billion. [1] 
The company also announced a new smartphone for $999.

2. Multi-Document Verification

docs = {
    "doc_financials": "Google Q4 advertising revenue reached $65.5 billion.",
    "doc_cloud": "Google Cloud revenue grew 25.6% year-over-year to $9.2 billion."
}

answer = "Google Cloud grew 25.6% to $9.2B, while advertising brought in $65.5B."

report = guard.verify(context=docs, answer=answer)
print(report.cited_answer)

3. Evaluating a RAG Benchmark Dataset

from ragground import RAGGround

guard = RAGGround()

rag_dataset = [
    {
        "context": "Python was created by Guido van Rossum and released in 1991.",
        "answer": "Guido van Rossum released Python in 1991."
    },
    {
        "context": "The speed of light in vacuum is 299,792 km/s.",
        "answer": "Light travels at 5,000,000 km/s."
    }
]

results = guard.evaluate_dataset(rag_dataset)

print(f"Overall Accuracy:       {results.accuracy * 100:.1f}%")
print(f"Hallucination Rate:     {results.hallucination_rate * 100:.1f}%")
print(f"Mean Latency:           {results.avg_latency_ms:.2f} ms")

# Export to CSV report
results.to_csv("rag_evaluation_results.csv")

4. Function Decorator for Python RAG Pipelines

from ragground.decorators import verify_grounding

@verify_grounding(raise_on_hallucination=False)
def generate_rag_response(query: str, context: str) -> str:
    # Your LLM call here
    return "LLM generated response..."

# Returns a GuardReport object directly
report = generate_rag_response(query="...", context="...")

⚙️ Configuration Options

Parameter Type Default Description
grounding_threshold float 0.75 Minimum entailment probability required to mark a claim as verified.
contradiction_threshold float 0.65 Probability threshold to classify a claim as contradicted.
deterministic_threshold float 0.80 Exact/fuzzy LCS threshold for sub-millisecond fast-path verification.
min_content_word_coverage float 0.75 Minimum ratio of non-stopword tokens in the claim present in source context.
split_compound_sentences bool False Split compound clauses (and, while) into sub-claim propositions.
default_citation_format CitationFormat BRACKET Format style: BRACKET ([1]), FOOTNOTE ([^1]), or TOOLTIP_HTML.

💻 CLI Usage

# Verify from terminal
ragground verify -c "Context text..." -a "Answer text..."

# Benchmark performance on your hardware
ragground benchmark

# Pre-download ONNX model cache
ragground download-model

📄 License

MIT License. Free for commercial and open-source use.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ragground-0.1.5.tar.gz (35.0 kB view details)

Uploaded Source

Built Distribution

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

ragground-0.1.5-py3-none-any.whl (28.5 kB view details)

Uploaded Python 3

File details

Details for the file ragground-0.1.5.tar.gz.

File metadata

  • Download URL: ragground-0.1.5.tar.gz
  • Upload date:
  • Size: 35.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for ragground-0.1.5.tar.gz
Algorithm Hash digest
SHA256 dd4705cf6a50fc84021dc0d32274541ff384a7c4bd25045fbb887f3f989e596a
MD5 1501bc276ec9b7410fc13bbb37225dcd
BLAKE2b-256 f52775dff2e23d2c8b1f6355c378d3558820fa9d38a52133a038f5748940bd09

See more details on using hashes here.

File details

Details for the file ragground-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: ragground-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 28.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for ragground-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 67b98eeedff5a4e0721198d98942beb1bcbe929d972ef1982c6026df3d7b0944
MD5 88351ce34a44f5f203892e891adaec4d
BLAKE2b-256 4a47e8ed9282c08882310c0a1c3f1f4d32a58043abb5ffb5c47aa95f25dc5374

See more details on using hashes here.

Release history Release notifications | RSS feed

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

This release

0.1.5 This release

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page