AISafeguards
AISafeguards is a Python package providing easy-to-use metrics for Retrieval-Augmented Generation (RAG) pipelines, including claim extraction and factuality evaluation.
Installation
pip install ai-safeguards
Features
- Claim Extraction: Extracts factual claims from text using LLMs or regex.
- Factuality Evaluation: Assesses if claims are supported by a given context.
- Faithfulness: Evaluates how much the RAG answer is grounded within the retrieved context.
- Answer Relevancy: Evaluates how much the RAG answer is relevant to the user's query/input.
- Contextual Relevancy: Evaluates how much the RAG retrieved context is relevant to the user's query/input.
- Extensible for additional RAG metrics and evaluation via cosine similarity (embeddings support).
Quick Start
from ai_safeguards import Safeguards
user_query = "What is the significance of the One Ring in The Lord of the Rings, and who forged it?"
llm_answer = "The One Ring, forged by Sauron in Mount Doom around SA 1600, was made to control the other Rings of Power. It grants invisibility and immense power but corrupts its wearer, like Gollum. Its destruction in Mount Doom defeats Sauron, as it holds his essence. However, the Ring was also crafted with Elven assistance in Eregion and could summon Nazgûl to its wearer instantly."
retrieved_context = "The One Ring was forged solely by the Dark Lord Sauron in the fires of Mount Doom in Mordor, circa SA 1600, during the Second Age. Its purpose was to dominate the bearers of the other Rings of Power, which were crafted by the Elves of Eregion under Sauron’s influence (though the Three Elven Rings were made by Celebrimbor alone). The Ring grants invisibility and amplifies power but corrupts its wearer, as seen with Gollum and Frodo. Sauron infused much of his power into the Ring, tying his fate to it; its destruction in Mount Doom at the end of the Third Age caused his downfall. Only the fires of Mount Doom could destroy the Ring."
safeguards = Safeguards(
api_key='YOUR_OPENAI_API_KEY',
model_name='gpt-4o-mini'
)
faithfulness_results = safeguards.faithfulness(
response=llm_answer,
context=retrieved_context,
claim_extraction_method='llm',
)
print(f"Faithfulness score: {faithfulness_results.score}")
print(f"Suported claims: {faithfulness_results.supported_claims}")
print(f"Unsuported claims: {faithfulness_results.non_supported_claims}")
Faithfulness score: 0.7777777777777778
Suported claims: ['The One Ring was forged by Sauron in Mount Doom around SA 1600.', 'The One Ring was made to control the other Rings of Power.', 'The One Ring grants invisibility and immense power.', 'The One Ring corrupts its wearer.', 'Gollum is an example of someone corrupted by the One Ring.', 'The destruction of the One Ring in Mount Doom defeats Sauron.', "The One Ring holds Sauron's essence."]
Unsuported claims: ['The One Ring was crafted with Elven assistance in Eregion.', 'The One Ring can summon Nazgûl to its wearer instantly.']
Project Structure
ai_safeguards/
safeguards.py
agents/
embedders/
prompts/
tests/
README.md
pyproject.toml
Contributing
Contributions are welcome! Please open issues or pull requests on GitHub.
License
This project is licensed under the MIT License. See LICENSE for details.
Metadata
Release files for ai-safeguards 0.0.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ai_safeguards-0.0.6.tar.gz | 8.9 kB | Without provenance | Details for ai_safeguards-0.0.6.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ai_safeguards-0.0.6-py3-none-any.whl | Python 3 | none | any | Details for ai_safeguards-0.0.6-py3-none-any.whl |
Total release size: 18.4 kB
Release files / ai_safeguards-0.0.6.tar.gz
| Download URL | ai_safeguards-0.0.6.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0a28a817d6c7eecb011d3d746e3f351520a3181220eaf8c9830150a157b79a64
|
|
BLAKE2b-256 checksum How to use checksums |
0591129f65b051e9366fd1906fb0adb50e250ab90c6d37eed375eb948c56cf1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.0
|
Release files / ai_safeguards-0.0.6-py3-none-any.whl
| Download URL | ai_safeguards-0.0.6-py3-none-any.whl |
|---|---|
| Size | 9.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f00238f92f1abc7f993cb3c760b2112826f5585cd7373307b966e534311a410c
|
|
BLAKE2b-256 checksum How to use checksums |
efc4152a559f39cec8271ab6f0865bbb22f69d64a900975cc34060aef545cc5a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.0
|
Security for ai-safeguards 0.0.6
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.