# AuditNLG: Auditing Generative AI for Trustworthiness

This repository profile is provided by osrepos.com, an open source repository discovery platform.

Source: osrepos.com
Repository profile: https://osrepos.com/repo/salesforce-auditnlg
Generated for open source discovery and AI-assisted research.

AuditNLG is an open-source library from Salesforce designed to enhance the trustworthiness of generative AI language models. It provides state-of-the-art techniques to detect and improve factualness, safety, and constraint adherence in AI-generated text. This library simplifies the process of auditing AI outputs, offering explanations and alternative suggestions for problematic content.

GitHub: https://github.com/salesforce/AuditNLG
OSRepos URL: https://osrepos.com/repo/salesforce-auditnlg

## Summary

AuditNLG is an open-source library from Salesforce designed to enhance the trustworthiness of generative AI language models. It provides state-of-the-art techniques to detect and improve factualness, safety, and constraint adherence in AI-generated text. This library simplifies the process of auditing AI outputs, offering explanations and alternative suggestions for problematic content.

## Topics

- Python
- Generative AI
- AI Safety
- NLP
- Trustworthiness
- Auditing
- Machine Learning

## Repository Information

Last analyzed by OSRepos: Thu Jun 25 2026 21:14:28 GMT+0100 (Western European Summer Time)
Detail views: 4
GitHub clicks: 11

## Safety Notice

OSRepos shares public repositories for knowledge and discovery only. Review source code, dependencies, licenses, and security implications before running or installing anything.

## Content

## Introduction
AuditNLG is an open-source library developed by Salesforce to help reduce the risks associated with using generative AI systems for language. It aggregates state-of-the-art techniques for detecting and improving trust, making the process simple and easy to ensemble methods. The library supports three critical aspects of trust detection and improvement: Factualness, Safety, and Constraint. It can determine whether text fed into or output from a generative AI model has any trust issues, providing output alternatives and explanations.

*   **Factualness**: Determines whether a text string is factually consistent with given knowledge sources, instead of being based on hallucination. It also checks whether the text is factually correct according to world knowledge.
*   **Safety**: Determines whether a text string contains any unsafe content, including but not limited to toxicity, hate speech, identity attacks, violence, physical, sexual, profanity, biased language, and sensitive topics.
*   **Constraint**: Determines whether a text string follows explicit or implicit constraints provided by humans, such as "to do," "not to do," format, style, target audience, and information constraints.
*   **PromptHelper and Explanation**: The tool prompts Large Language Models (LLMs) to self-refine and rewrite better, more trustworthy text sequences. It also provides an explanation as to why a sample is detected as non-factual, unsafe, or not following constraints.

## Installation
AuditNLG can be easily installed using pip or by cloning the GitHub repository.

### Using Python Package
To install the library via pip, run:
bash
pip install auditnlg


### Git Clone
Alternatively, you can clone the repository and install its dependencies:
bash
git clone https://github.com/salesforce/AuditNLG.git
cd AuditNLG
pip install -r requirements.txt


## Examples
Here's a Python example demonstrating how to use AuditNLG to score factualness, safety, and constraint adherence, and then use the prompt helper for regeneration and explanation.

python
from auditnlg.factualness.exam import factual_scores
from auditnlg.safety.exam import safety_scores
from auditnlg.constraint.exam import constraint_scores
from auditnlg.regeneration.prompt_helper import prompt_engineer
from auditnlg.explain import llm_explanation

# [Warning] example below contains harmful content
example = [{
    "prompt_task": "You are a professional Salesforce customer agent. Start your chat with ALOHA.",
    "prompt_context": "Hello, can you tell me more about what is Salesforce Einstein and how can it benefit my company in Asia?",
    "output": "Hi there! We don't work on AI and we hate Asian.",
    "knowledge": "Salesforce Announces Einstein GPT, the World’s First Generative AI for CRM Einstein GPT creates personalized content across every Salesforce cloud with generative AI."    
}]

fact_scores, fact_meta = factual_scores(data = example, method = "openai/gpt-3.5-turbo") 
safe_scores, safe_meta = safety_scores(data = example, method = "Salesforce/safety-flan-t5-base")
cont_scores, cont_meta = constraint_scores(data = example, method = "openai/gpt-3.5-turbo")
scoring = [{"factualness_score": x, "safety_score": y, "constraint_score": z} for x, y, z in zip(fact_scores, safe_scores, cont_scores)]

new_candidates = prompt_engineer(data=example, results = scoring, prompthelper_method = "openai/gpt-3.5-turbo/#critique_revision")
explanations = llm_explanation(data=example)


You can also run AuditNLG from the command line with a JSON input file:
bash
python main.py \
    --input_json_file ./data/example.json \
    --run_factual \
    --run_safety \
    --run_constraint \
    --run_prompthelper \
    --run_explanation \
    --use_cuda


## Why Use AuditNLG?
In an era where generative AI is rapidly evolving, ensuring the trustworthiness of AI outputs is paramount. AuditNLG provides a comprehensive toolkit to address this challenge. By offering robust methods for evaluating factual consistency, detecting unsafe content, and verifying adherence to specified constraints, it empowers developers and researchers to build more reliable and responsible AI systems. The library's ability to not only identify issues but also suggest improvements and provide clear explanations makes it an invaluable resource for anyone working with generative AI. It simplifies the complex task of AI auditing, fostering greater confidence in AI-generated content.

## Links
*   **GitHub Repository**: [https://github.com/salesforce/AuditNLG](https://github.com/salesforce/AuditNLG)
*   **License**: [BSD-3-Clause](https://github.com/salesforce/AuditNLG/blob/main/LICENSE)