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.4.tar.gz (34.6 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.4-py3-none-any.whl (25.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ragground-0.1.4.tar.gz
  • Upload date:
  • Size: 34.6 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.4.tar.gz
Algorithm Hash digest
SHA256 accba1de88162e542c0f3cde54eafec4e2314503a1ebfdb3964c2bf694abf247
MD5 d433c047b99a57bb4c4290a71e14ebed
BLAKE2b-256 5a20375226fb6de55c38799d394b24941e9b18bc99000614fb17e63d7f79bbd2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: ragground-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 25.9 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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b4b42f84c21d2136fcbd7ee7ca2fb9c5c177ba5a58e2130389d58742c9ad585b
MD5 1061951b364a5b2d623542409bb64152
BLAKE2b-256 6279778575c0c0a1b0303404d4a13556a8e7290af079f51a5ebfab609eaaae22

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

This release

0.1.4 This release

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