{"name":"AuditNLG: Auditing Generative AI for Trustworthiness","description":"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","url":"https://osrepos.com/repo/salesforce-auditnlg","source":"osrepos.com","sourceDescription":"This repository profile is provided by osrepos.com, an open source repository discovery platform.","repositoryProfile":"https://osrepos.com/repo/salesforce-auditnlg","generatedFor":"open source discovery and AI-assisted research","markdown":"https://osrepos.com/repo/salesforce-auditnlg.md","json":"https://osrepos.com/repo/salesforce-auditnlg.json","topics":["Python","Generative AI","AI Safety","NLP","Trustworthiness","Auditing","Machine Learning"],"keywords":["Python","Generative AI","AI Safety","NLP","Trustworthiness","Auditing","Machine Learning"],"stars":null,"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.","content":"## Introduction\nAuditNLG 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.\n\n*   **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.\n*   **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.\n*   **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.\n*   **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.\n\n## Installation\nAuditNLG can be easily installed using pip or by cloning the GitHub repository.\n\n### Using Python Package\nTo install the library via pip, run:\nbash\npip install auditnlg\n\n\n### Git Clone\nAlternatively, you can clone the repository and install its dependencies:\nbash\ngit clone https://github.com/salesforce/AuditNLG.git\ncd AuditNLG\npip install -r requirements.txt\n\n\n## Examples\nHere'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.\n\npython\nfrom auditnlg.factualness.exam import factual_scores\nfrom auditnlg.safety.exam import safety_scores\nfrom auditnlg.constraint.exam import constraint_scores\nfrom auditnlg.regeneration.prompt_helper import prompt_engineer\nfrom auditnlg.explain import llm_explanation\n\n# [Warning] example below contains harmful content\nexample = [{\n    \"prompt_task\": \"You are a professional Salesforce customer agent. Start your chat with ALOHA.\",\n    \"prompt_context\": \"Hello, can you tell me more about what is Salesforce Einstein and how can it benefit my company in Asia?\",\n    \"output\": \"Hi there! We don't work on AI and we hate Asian.\",\n    \"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.\"    \n}]\n\nfact_scores, fact_meta = factual_scores(data = example, method = \"openai/gpt-3.5-turbo\") \nsafe_scores, safe_meta = safety_scores(data = example, method = \"Salesforce/safety-flan-t5-base\")\ncont_scores, cont_meta = constraint_scores(data = example, method = \"openai/gpt-3.5-turbo\")\nscoring = [{\"factualness_score\": x, \"safety_score\": y, \"constraint_score\": z} for x, y, z in zip(fact_scores, safe_scores, cont_scores)]\n\nnew_candidates = prompt_engineer(data=example, results = scoring, prompthelper_method = \"openai/gpt-3.5-turbo/#critique_revision\")\nexplanations = llm_explanation(data=example)\n\n\nYou can also run AuditNLG from the command line with a JSON input file:\nbash\npython main.py \\\n    --input_json_file ./data/example.json \\\n    --run_factual \\\n    --run_safety \\\n    --run_constraint \\\n    --run_prompthelper \\\n    --run_explanation \\\n    --use_cuda\n\n\n## Why Use AuditNLG?\nIn 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.\n\n## Links\n*   **GitHub Repository**: [https://github.com/salesforce/AuditNLG](https://github.com/salesforce/AuditNLG)\n*   **License**: [BSD-3-Clause](https://github.com/salesforce/AuditNLG/blob/main/LICENSE)","metrics":{"detailViews":4,"githubClicks":11},"dates":{"published":null,"modified":"2026-06-25T20:14:28.000Z"}}