Favicon of LLM Guard

LLM Guard

A Python LLM security toolkit you can deploy as an API to screen prompts and responses. MIT licensed; archived and no longer maintained.

Screenshot of LLM Guard website

LLM Guard is a Python security toolkit developers can deploy as a self-hosted API to check prompts and model responses in their applications. It provides screening and sanitization rather than running the application's LLM. The project is archived and no longer maintained, including its associated Hugging Face models.

Its prompt scanners detect injection attempts, exposed secrets, invisible text and toxic language. An anonymization scanner removes identifying information from prompts, while an output scanner can restore anonymized details in responses. Other checks flag sensitive information in generated text.

Content controls cover unwanted topics, competitor mentions, code and text patterns. Developers can also check language, detect gibberish and restrict prompt length by token count. The separate input and output scanners let applications apply different checks before and after a model request.

Response scanners assess relevance to the prompt, factual consistency and bias. They also check for malicious URLs, valid JSON and whether the response uses the same language as the prompt. These are individual checks rather than a guarantee that an answer is safe or correct.

The toolkit includes an example integration with ChatGPT through the OpenAI API; deploying the screening service yourself doesn't make that model inference local. The code is open source under the MIT license.

Similar to LLM Guard