LLM Guard is a Python toolkit from Protect AI for securing the traffic between an application and a large language model. It applies scanners to prompts before they reach the model and to responses before they reach the user, covering sanitisation, harmful-language detection, data-leakage prevention, and prompt-injection resistance. The project and its models on Hugging Face are archived and no longer maintained.
Scanners compose as pipelines: 15 prompt scanners and 21 output scanners, each independently configurable. Base functionality needs few libraries, with additional dependencies installed on demand as more advanced scanners are used. Python 3.9 or higher is required, and the toolkit can be deployed as a standalone API service or called from application code, with an example for the OpenAI chat API.
Features
- Prompt scanners: Anonymize, BanCode, BanCompetitors, BanSubstrings, BanTopics, Code, Gibberish, InvisibleText, Language, PromptInjection, Regex, Secrets, Sentiment, TokenLimit, and Toxicity
- Output scanners: BanCode, BanCompetitors, BanSubstrings, BanTopics, Bias, Code, Deanonymize, JSON, Language, LanguageSame, MaliciousURLs, NoRefusal, ReadingTime, FactualConsistency, Gibberish, Regex, Relevance, Sensitive, Sentiment, Toxicity, and URLReachability
- Anonymise and deanonymise: PII is replaced before the prompt is sent and restored in the response
- API deployment: runs as an HTTP service in front of a model
- Playground: a Hugging Face Space for trying scanners interactively
