LLM Guard is a Python security toolkit that sits around LLM interactions, filtering both the prompts sent to a model and the responses it returns. It targets teams running LLMs in production who need to sanitize inputs, detect harmful or sensitive content, prevent data leakage, and resist prompt-injection attacks. It works as a library integrated into application code and can also be deployed as an API.
Protection is built from composable scanners applied to inputs and outputs. Input scanners include Anonymize, BanCode, BanCompetitors, BanSubstrings, BanTopics, Code, Gibberish, InvisibleText, Language, PromptInjection, Regex, Secrets, Sentiment, TokenLimit, and Toxicity. Output scanners cover concerns such as Bias, Deanonymize, JSON validation, MaliciousURLs, NoRefusal, FactualConsistency, Relevance, Sensitive-data detection, URLReachability, and language, sentiment, and toxicity checks. Scanners can be combined to enforce the checks a given application needs.
Base installation pulls in a limited set of dependencies, with heavier libraries installed automatically as more advanced scanners are used. It requires Python 3.9 or higher.
