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.3.tar.gz (34.1 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.3-py3-none-any.whl (25.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ragground-0.1.3.tar.gz
  • Upload date:
  • Size: 34.1 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.3.tar.gz
Algorithm Hash digest
SHA256 1a448463d6f726cfd19cc764195c2ffa5bd8d3cc420e59277f6cbc643bcb1abf
MD5 60392b484e7178891c58d1e2e4ad8ec3
BLAKE2b-256 19d17d95bd6ed9fe55b9156c4f79b1ce2f51f09a95fc1da4ad069172318d7107

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ragground-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 25.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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ebceb581e73e8247c9eb0644865fbf08e4425d5a9cda9337d30f88ee0248125a
MD5 0a7ed91e2a91ff430166d2bc85d65458
BLAKE2b-256 c649dbce57d5c1cd738aeb01c5737b174b92baa9f8a9b88aca3d1dea75e07664

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

0.1.5

2 files

0.1.4

2 files

This release

0.1.3 This release

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