Skip to main content

GATRAG

Guarded Abstention / Answering for Retrieval-Augmented Generation (RAG)

GATRAG is a lightweight context-sufficiency gate for RAG pipelines. It sits between the retriever and the LLM/generator, evaluates whether retrieved passages contain enough information to answer a user's query, filters weak passages, and provides an explicit generate / abstain decision.

Instead of always sending retrieved documents to an LLM, GATRAG uses an NLI cross-encoder to estimate whether the retrieved context actually supports the query.

Core idea: retrieve → validate context → generate only when the context is sufficient.

This can help RAG applications reduce unnecessary generation, expose an inspectable confidence signal, and avoid confidently answering when retrieval produced weak or irrelevant context.

Features

NLI-based context sufficiency classification.

Per-document relevance/sufficiency scoring.

Document filtering and ranking.

Optional whole-context ("packed") scoring.

Explicit SUFFICIENT, INSUFFICIENT, and UNCERTAIN results.

Simple boolean generation gate through validate_context_simple().

Batch validation through batch_validate().

Supports plain strings, SimpleDocument, and document-like objects exposing page_content and optional metadata.

Configurable score thresholds, uncertainty margins, model, device, batching, context length, and ranking limits.

Optional conservative fallback when model inference fails.

Compatible with CPU and CUDA environments.

Small public API with typed configuration and inspectable results.

Installation

Basic installation

pip install gatrag-context-classifier

Model-enabled installation

The default classifier loads an NLI model through sentence-transformers. Install the model extra:

pip install "gatrag[model]"

Or with uv:

uv add "gatrag[model]"

The default model is:

cross-encoder/nli-deberta-v3-small

The model is loaded automatically when ContextSufficientClassifier is created without a custom model.

Metadata

Release files for gatrag-context-classifier 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gatrag-context-classifier 1.0.0
File Size Uploaded Provenance Actions
gatrag_context_classifier-1.0.0.tar.gz 2.0 kB Without provenance Details for gatrag_context_classifier-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for gatrag-context-classifier 1.0.0
File Interpreter ABI Platform Actions
gatrag_context_classifier-1.0.0-py3-none-any.whl Python 3 none any Details for gatrag_context_classifier-1.0.0-py3-none-any.whl

Total release size: 4.2 kB

Release files / gatrag_context_classifier-1.0.0.tar.gz

Download URL gatrag_context_classifier-1.0.0.tar.gz
Size 2.0 kB
Tags Source
SHA-256 checksum
How to use checksums
b6ab577e99978f6774031d2976e1c8645223093f5dad9cc13be776d132c5dfee
BLAKE2b-256 checksum
How to use checksums
763c7cc2a7c27b6bab8abf134225615d3ebaf93561a08e630b0d610a0ea649d4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.15

Release files / gatrag_context_classifier-1.0.0-py3-none-any.whl

Download URL gatrag_context_classifier-1.0.0-py3-none-any.whl
Size 2.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
86a558755bb95f18bcc6e09139ba6b6c57cc4ca3ebe9038269112bb199f26f78
BLAKE2b-256 checksum
How to use checksums
ca3e9af173df45844a3e7be6e04bb88d6f5b2d75506c6213d4ed521428a2b8ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.15

Security for gatrag-context-classifier 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

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