Metadata-Version: 2.4
Name: groundanchor
Version: 0.1.0
Summary: Deterministic factual grounding and hallucination verification engine for AI agents and RAG
Author: groundanchor Contributors
License: MIT
Project-URL: Homepage, https://github.com/VikasPatel22/groundanchor
Project-URL: Repository, https://github.com/VikasPatel22/groundanchor.git
Keywords: hallucination,rag,verification,grounding,ai-safety,agents
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# groundanchor

Deterministic factual grounding and hallucination verification engine for AI agents and RAG pipelines.

Engineered for production teams needing fast, sub-millisecond, zero-API-cost verification of LLM responses against source documents without relying on slow or non-deterministic LLM-as-a-judge calls.

---

## Key Capabilities

- **Zero-API-Cost & Ultra-Low Latency**: Pure deterministic Python engine running in sub-50 milliseconds on CPU.
- **Numerical & Entity Anchor Verification**: Detects subtle numerical contradictions (e.g. source says `14%`, LLM generates `18%`), currency discrepancies, and unauthorized entity insertions.
- **Polarity & Negation Check**: Catches negation inversions (e.g. source states *"service is not supported"*, LLM generates *"service is supported"*).
- **Attribution Index**: Computes composite lexical overlap, longest common subsequence, and Okapi BM25 citation scores.
- **Automatic Sanitization**: Strips ungrounded claims on the fly, outputting only verified statements.
- **Drop-in Guardrail Decorator**: `@groundanchor.guard` decorates sync and async LLM functions with `raise`, `sanitize`, or `warn` policies.

---

## Installation

```bash
pip install groundanchor
```

---

## Quickstart

```python
import groundanchor

sources = [
    "EdgeMind is an open-source Python SDK engineered for local AI image generation. "
    "It supports 1-step Hyper-SD acceleration and runs natively on Windows, Linux, and macOS."
]

response = (
    "EdgeMind is a Python SDK for local AI image generation supporting 1-step acceleration. "
    "It was acquired by an offshore entity for $500M."
)

report = groundanchor.verify(sources=sources, response=response)

print(f"Is Grounded: {report.is_grounded}")        # False
print(f"Grounding Score: {report.grounding_score}")  # 0.48
print(f"Risk Level: {report.risk_level.value}")     # ungrounded

# Sanitize to keep only verified claims:
print(report.sanitized_response())
# Output: "EdgeMind is a Python SDK for local AI image generation supporting 1-step acceleration."
```

---

## Production Guardrail Decorator

```python
from groundanchor import guard, GroundingViolationError

@guard(threshold=0.80, action="sanitize")
def answer_rag(sources: list[str], question: str) -> str:
    # Any LLM call here (OpenAI, Anthropic, Ollama, local models)
    return llm.generate(sources, question)
```

---

## CLI Usage

Audit responses directly in CI/CD or shell pipelines:

```bash
groundanchor verify --context docs.txt --response output.txt --threshold 0.75
groundanchor sanitize --context docs.txt --response output.txt
groundanchor redline --context docs.txt --response output.txt
```

---

## License

MIT License.
