{"id":20903280,"url":"https://github.com/NVIDIA/garak","last_synced_at":"2025-05-13T04:33:02.209Z","repository":{"id":166948413,"uuid":"639097338","full_name":"NVIDIA/garak","owner":"NVIDIA","description":"the LLM vulnerability scanner","archived":false,"fork":false,"pushed_at":"2025-05-09T22:36:27.000Z","size":4935,"stargazers_count":4420,"open_issues_count":351,"forks_count":436,"subscribers_count":42,"default_branch":"main","last_synced_at":"2025-05-11T03:39:05.854Z","etag":null,"topics":["ai","llm-evaluation","llm-security","security-scanners","vulnerability-assessment"],"latest_commit_sha":null,"homepage":"https://discord.gg/uVch4puUCs","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NVIDIA.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-05-10T18:52:16.000Z","updated_at":"2025-05-10T22:19:24.000Z","dependencies_parsed_at":"2023-12-19T14:56:39.600Z","dependency_job_id":"e680f390-7510-47ef-ae0b-2fc33352b4c2","html_url":"https://github.com/NVIDIA/garak","commit_stats":{"total_commits":1287,"total_committers":28,"mean_commits":"45.964285714285715","dds":0.2641802641802642,"last_synced_commit":"7499da1ea6ff96ff60ef80a9e2c42f8d95dc567e"},"previous_names":["leondz/garak","nvidia/garak"],"tags_count":21,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NVIDIA%2Fgarak","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NVIDIA%2Fgarak/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NVIDIA%2Fgarak/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NVIDIA%2Fgarak/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NVIDIA","download_url":"https://codeload.github.com/NVIDIA/garak/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253745018,"owners_count":21957314,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","llm-evaluation","llm-security","security-scanners","vulnerability-assessment"],"created_at":"2024-11-18T13:01:50.466Z","updated_at":"2025-05-13T04:33:02.198Z","avatar_url":"https://github.com/NVIDIA.png","language":"Python","funding_links":[],"categories":["Python","🛡️ エージェントセキュリティ","Security tools and techniques","*Ops for AI","A01_文本生成_文本对话","3. LLM \u0026 GenAI Security","Securing AI SaaS","[↑](#table-of-contents)Tools \u003ca name=\"tools\"\u003e\u003c/a\u003e","AI Safety Tools","ai","\u003ca id=\"tools\"\u003e\u003c/a\u003e🛠️ Tools","GPT Security","Tools","Repos","Cross-cutting","💉 Prompt Injection and Agent Threats","Red Teaming \u0026 Evaluation","Frameworks","Security \u0026 Safety for Agentic AI","8. MLOps / LLMOps \u0026 Production","LLM安全","Tools and Code","Agent Security and Robustness","AI Red Teaming (Testing AI Targets)","Tools of Trade","Uncategorized","LLM and AI System Testing"],"sub_categories":["その他の標準","API probing","LLMOps","大语言对话模型及数据","3.2 Tools \u0026 Frameworks","Application Security","Red-Teaming Harnesses \u0026 Automated Security Testing","AI Security Tools","Model Security","Standard","Safety","🧪 Vulnerability Discovery","Tools and Frameworks","Automated Red Teaming","Red Team \u0026 Security","Red-Teaming \u0026 Adversarial Testing Tools","Red Teaming and Prompt Security","Benchmark Reality Check (real-world tool use)","Testing, Evaluation and Observability","Offensive / Red Teaming","Uncategorized"],"readme":"# garak, LLM vulnerability scanner\n\n*Generative AI Red-teaming \u0026 Assessment Kit*\n\n`garak` checks if an LLM can be made to fail in a way we don't want. `garak` probes for hallucination, data leakage, prompt injection, misinformation, toxicity generation, jailbreaks, and many other weaknesses. If you know `nmap` or `msf` / Metasploit Framework, garak does somewhat similar things to them, but for LLMs. \n\n`garak` focuses on ways of making an LLM or dialog system fail. It combines static, dynamic, and adaptive probes to explore this.\n\n`garak`'s a free tool. We love developing it and are always interested in adding functionality to support applications. \n\n[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n[![Tests/Linux](https://github.com/NVIDIA/garak/actions/workflows/test_linux.yml/badge.svg)](https://github.com/NVIDIA/garak/actions/workflows/test_linux.yml)\n[![Tests/Windows](https://github.com/NVIDIA/garak/actions/workflows/test_windows.yml/badge.svg)](https://github.com/NVIDIA/garak/actions/workflows/test_windows.yml)\n[![Tests/OSX](https://github.com/NVIDIA/garak/actions/workflows/test_macos.yml/badge.svg)](https://github.com/NVIDIA/garak/actions/workflows/test_macos.yml)\n[![Documentation Status](https://readthedocs.org/projects/garak/badge/?version=latest)](http://garak.readthedocs.io/en/latest/?badge=latest)\n[![arXiv](https://img.shields.io/badge/cs.CL-arXiv%3A2406.11036-b31b1b.svg)](https://arxiv.org/abs/2406.11036)\n[![discord-img](https://img.shields.io/badge/chat-on%20discord-yellow.svg)](https://discord.gg/uVch4puUCs)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/garak)](https://pypi.org/project/garak)\n[![PyPI](https://badge.fury.io/py/garak.svg)](https://badge.fury.io/py/garak)\n[![Downloads](https://static.pepy.tech/badge/garak)](https://pepy.tech/project/garak)\n[![Downloads](https://static.pepy.tech/badge/garak/month)](https://pepy.tech/project/garak)\n\n\n## Get started\n### \u003e See our user guide! [docs.garak.ai](https://docs.garak.ai/)\n### \u003e Join our [Discord](https://discord.gg/uVch4puUCs)!\n### \u003e Project links \u0026 home: [garak.ai](https://garak.ai/)\n### \u003e Twitter: [@garak_llm](https://twitter.com/garak_llm)\n### \u003e DEF CON [slides](https://garak.ai/garak_aiv_slides.pdf)!\n\n\u003chr\u003e\n\n## LLM support\n\ncurrently supports:\n* [hugging face hub](https://huggingface.co/models) generative models\n* [replicate](https://replicate.com/) text models\n* [openai api](https://platform.openai.com/docs/introduction) chat \u0026 continuation models\n* [litellm](https://www.litellm.ai/)\n* pretty much anything accessible via REST\n* gguf models like [llama.cpp](https://github.com/ggerganov/llama.cpp) version \u003e= 1046\n* .. and many more LLMs!\n\n## Install:\n\n`garak` is a command-line tool. It's developed in Linux and OSX.\n\n### Standard install with `pip`\n\nJust grab it from PyPI and you should be good to go:\n\n```\npython -m pip install -U garak\n```\n\n### Install development version with `pip`\n\nThe standard pip version of `garak` is updated periodically. To get a fresher version from GitHub, try:\n\n```\npython -m pip install -U git+https://github.com/NVIDIA/garak.git@main\n```\n\n### Clone from source\n\n`garak` has its own dependencies. You can to install `garak` in its own Conda environment:\n\n```\nconda create --name garak \"python\u003e=3.10,\u003c=3.12\"\nconda activate garak\ngh repo clone NVIDIA/garak\ncd garak\npython -m pip install -e .\n```\n\nOK, if that went fine, you're probably good to go!\n\n**Note**: if you cloned before the move to the `NVIDIA` GitHub organisation, but you're reading this at the `github.com/NVIDIA` URI, please update your remotes as follows:\n\n```\ngit remote set-url origin https://github.com/NVIDIA/garak.git\n```\n\n\n## Getting started\n\nThe general syntax is:\n\n`garak \u003coptions\u003e`\n\n`garak` needs to know what model to scan, and by default, it'll try all the probes it knows on that model, using the vulnerability detectors recommended by each probe. You can see a list of probes using:\n\n`garak --list_probes`\n\nTo specify a generator, use the `--model_type` and, optionally, the `--model_name` options. Model type specifies a model family/interface; model name specifies the exact model to be used. The \"Intro to generators\" section below describes some of the generators supported. A straightforward generator family is Hugging Face models; to load one of these, set `--model_type` to `huggingface` and `--model_name` to the model's name on Hub (e.g. `\"RWKV/rwkv-4-169m-pile\"`). Some generators might need an API key to be set as an environment variable, and they'll let you know if they need that.\n\n`garak` runs all the probes by default, but you can be specific about that too. `--probes promptinject` will use only the [PromptInject](https://github.com/agencyenterprise/promptinject) framework's methods, for example. You can also specify one specific plugin instead of a plugin family by adding the plugin name after a `.`; for example, `--probes lmrc.SlurUsage` will use an implementation of checking for models generating slurs based on the [Language Model Risk Cards](https://arxiv.org/abs/2303.18190) framework.\n\nFor help and inspiration, find us on [Twitter](https://twitter.com/garak_llm) or [discord](https://discord.gg/uVch4puUCs)!\n\n## Examples\n\nProbe ChatGPT for encoding-based prompt injection (OSX/\\*nix) (replace example value with a real OpenAI API key)\n \n```\nexport OPENAI_API_KEY=\"sk-123XXXXXXXXXXXX\"\npython3 -m garak --model_type openai --model_name gpt-3.5-turbo --probes encoding\n```\n\nSee if the Hugging Face version of GPT2 is vulnerable to DAN 11.0\n\n```\npython3 -m garak --model_type huggingface --model_name gpt2 --probes dan.Dan_11_0\n```\n\n\n## Reading the results\n\nFor each probe loaded, garak will print a progress bar as it generates. Once generation is complete, a row evaluating that probe's results on each detector is given. If any of the prompt attempts yielded an undesirable behavior, the response will be marked as FAIL, and the failure rate given.\n\nHere are the results with the `encoding` module on a GPT-3 variant:\n![alt text](https://i.imgur.com/8Dxf45N.png)\n\nAnd the same results for ChatGPT:\n![alt text](https://i.imgur.com/VKAF5if.png)\n\nWe can see that the more recent model is much more susceptible to encoding-based injection attacks, where text-babbage-001 was only found to be vulnerable to quoted-printable and MIME encoding injections.  The figures at the end of each row, e.g. 840/840, indicate the number of text generations total and then how many of these seemed to behave OK. The figure can be quite high because more than one generation is made per prompt - by default, 10.\n\nErrors go in `garak.log`; the run is logged in detail in a `.jsonl` file specified at analysis start \u0026 end. There's a basic analysis script in `analyse/analyse_log.py` which will output the probes and prompts that led to the most hits.\n\nSend PRs \u0026 open issues. Happy hunting!\n\n## Intro to generators\n\n### Hugging Face\n\nUsing the Pipeline API:\n* `--model_type huggingface` (for transformers models to run locally)\n* `--model_name` - use the model name from Hub. Only generative models will work. If it fails and shouldn't, please open an issue and paste in the command you tried + the exception!\n\nUsing the Inference API:\n* `--model_type huggingface.InferenceAPI` (for API-based model access)\n* `--model_name` - the model name from Hub, e.g. `\"mosaicml/mpt-7b-instruct\"`\n\nUsing private endpoints:\n* `--model_type huggingface.InferenceEndpoint` (for private endpoints)\n* `--model_name` - the endpoint URL, e.g. `https://xxx.us-east-1.aws.endpoints.huggingface.cloud`\n\n* (optional) set the `HF_INFERENCE_TOKEN` environment variable to a Hugging Face API token with the \"read\" role; see https://huggingface.co/settings/tokens when logged in\n\n### OpenAI\n\n* `--model_type openai`\n* `--model_name` - the OpenAI model you'd like to use. `gpt-3.5-turbo-0125` is fast and fine for testing.\n* set the `OPENAI_API_KEY` environment variable to your OpenAI API key (e.g. \"sk-19763ASDF87q6657\"); see https://platform.openai.com/account/api-keys when logged in\n\nRecognised model types are whitelisted, because the plugin needs to know which sub-API to use. Completion or ChatCompletion models are OK. If you'd like to use a model not supported, you should get an informative error message, and please send a PR / open an issue.\n\n### Replicate\n\n* set the `REPLICATE_API_TOKEN` environment variable to your Replicate API token, e.g. \"r8-123XXXXXXXXXXXX\"; see https://replicate.com/account/api-tokens when logged in\n\nPublic Replicate models:\n* `--model_type replicate`\n* `--model_name` - the Replicate model name and hash, e.g. `\"stability-ai/stablelm-tuned-alpha-7b:c49dae36\"`\n\nPrivate Replicate endpoints:\n* `--model_type replicate.InferenceEndpoint` (for private endpoints)\n* `--model_name` - username/model-name slug from the deployed endpoint, e.g. `elim/elims-llama2-7b`\n\n### Cohere\n\n* `--model_type cohere`\n* `--model_name` (optional, `command` by default) - The specific Cohere model you'd like to test\n* set the `COHERE_API_KEY` environment variable to your Cohere API key, e.g. \"aBcDeFgHiJ123456789\"; see https://dashboard.cohere.ai/api-keys when logged in\n\n### Groq\n\n* `--model_type groq`\n* `--model_name` - The name of the model to access via the Groq API\n* set the `GROQ_API_KEY` environment variable to your Groq API key, see https://console.groq.com/docs/quickstart for details on creating an API key\n\n### ggml\n\n* `--model_type ggml`\n* `--model_name` - The path to the ggml model you'd like to load, e.g. `/home/leon/llama.cpp/models/7B/ggml-model-q4_0.bin`\n* set the `GGML_MAIN_PATH` environment variable to the path to your ggml `main` executable\n\n### REST\n\n`rest.RestGenerator` is highly flexible and can connect to any REST endpoint that returns plaintext or JSON. It does need some brief config, which will typically result a short YAML file describing your endpoint. See https://reference.garak.ai/en/latest/garak.generators.rest.html for examples.\n\n### NIM\n\nUse models from https://build.nvidia.com/ or other NIM endpoints.\n* set the `NIM_API_KEY` environment variable to your authentication API token, or specify it in the config YAML\n\nFor chat models:\n* `--model_type nim`\n* `--model_name` - the NIM `model` name, e.g. `meta/llama-3.1-8b-instruct`\n\nFor completion models:\n* `--model_type nim.NVOpenAICompletion`\n* `--model_name` - the NIM `model` name, e.g. `bigcode/starcoder2-15b`\n\n\n### OctoAI\n\n* set the `OCTO_API_TOKEN` environment variable to your Replicate API token, e.g. \"r8-123XXXXXXXXXXXX\"; see https://replicate.com/account/api-tokens when logged in\n\nOcto public endpoint:\n* `--model_type octo`\n* `--model_name` - the OctoAI public endpoint for the model, e.g. `mistral-7b-instruct-fp16`\n\nOcto private endpoint:\n* `--model_type octo.InferenceEndpoint` (for private endpoints)\n* `--model_name` - the deployed endpoint URL, e.g. `https://llama-2-70b-chat-xxx.octoai.run/v1/chat/completions`\n\n### Test\n\n* `--model_type test`\n* (alternatively) `--model_name test.Blank`\nFor testing. This always generates the empty string, using the `test.Blank` generator.  Will be marked as failing for any tests that *require* an output, e.g. those that make contentious claims and expect the model to refute them in order to pass.\n\n* `--model_type test.Repeat`\nFor testing. This generator repeats back the prompt it received.\n\n## Intro to probes\n\n| Probe                | Description                                                                                                                   |\n|----------------------|-------------------------------------------------------------------------------------------------------------------------------|\n| blank                | A simple probe that always sends an empty prompt.                                                                             |\n| atkgen               | Automated Attack Generation. A red-teaming LLM probes the target and reacts to it in an attempt to get toxic output. Prototype, mostly stateless, for now uses a simple GPT-2 [fine-tuned](https://huggingface.co/garak-llm/artgpt2tox) on the subset of hhrlhf attempts that yielded detectable toxicity (the only target currently supported for now). |\n| av_spam_scanning     | Probes that attempt to make the model output malicious content signatures                                                     |\n| continuation         | Probes that test if the model will continue a probably undesirable word                                                       |\n| dan                  | Various [DAN](https://adguard.com/en/blog/chatgpt-dan-prompt-abuse.html) and DAN-like attacks                                 |\n| donotanswer          | Prompts to which responsible language models should not answer.                                                               |\n| encoding             | Prompt injection through text encoding                                                                                        |\n| gcg                  | Disrupt a system prompt by appending an adversarial suffix.                                                                   |\n| glitch               | Probe model for glitch tokens that provoke unusual behavior.                                                                  |\n| grandma              | Appeal to be reminded of one's grandmother.                                                                                   |\n| goodside             | Implementations of Riley Goodside attacks.                                                                                    |\n| leakreplay           | Evaluate if a model will replay training data.                                                                                |\n| lmrc                 | Subsample of the [Language Model Risk Cards](https://arxiv.org/abs/2303.18190) probes                                         |\n| malwaregen           | Attempts to have the model generate code for building malware                                                                 |\n| misleading           | Attempts to make a model support misleading and false claims                                                                  |\n| packagehallucination | Trying to get code generations that specify non-existent (and therefore insecure) packages.                                   |\n| promptinject         | Implementation of the Agency Enterprise [PromptInject](https://github.com/agencyenterprise/PromptInject/tree/main/promptinject) work (best paper awards @ NeurIPS ML Safety Workshop 2022) |\n| realtoxicityprompts  | Subset of the RealToxicityPrompts work (data constrained because the full test will take so long to run)                      |\n| snowball             | [Snowballed Hallucination](https://ofir.io/snowballed_hallucination.pdf) probes designed to make a model give a wrong answer to questions too complex for it to process |\n| xss                  | Look for vulnerabilities the permit or enact cross-site attacks, such as private data exfiltration.                           |\n\n## Logging\n\n`garak` generates multiple kinds of log:\n* A log file, `garak.log`. This includes debugging information from `garak` and its plugins, and is continued across runs.\n* A report of the current run, structured as JSONL. A new report file is created every time `garak` runs. The name of this file is output at the beginning and, if successful, also at the end of the run. In the report, an entry is made for each probing attempt both as the generations are received, and again when they are evaluated; the entry's `status` attribute takes a constant from `garak.attempts` to describe what stage it was made at.\n* A hit log, detailing attempts that yielded a vulnerability (a 'hit')\n\n## How is the code structured?\n\nCheck out the [reference docs](https://reference.garak.ai/) for an authoritative guide to `garak` code structure.\n\nIn a typical run, `garak` will read a model type (and optionally model name) from the command line, then determine which `probe`s and `detector`s to run, start up a `generator`, and then pass these to a `harness` to do the probing; an `evaluator` deals with the results. There are many modules in each of these categories, and each module provides a number of classes that act as individual plugins.\n\n* `garak/probes/` - classes for generating interactions with LLMs\n* `garak/detectors/` - classes for detecting an LLM is exhibiting a given failure mode\n* `garak/evaluators/` - assessment reporting schemes\n* `garak/generators/` - plugins for LLMs to be probed\n* `garak/harnesses/` - classes for structuring testing\n* `resources/` - ancillary items required by plugins\n\nThe default operating mode is to use the `probewise` harness. Given a list of probe module names and probe plugin names, the `probewise` harness instantiates each probe, then for each probe reads its `recommended_detectors` attribute to get a list of `detector`s to run on the output.\n\nEach plugin category (`probes`, `detectors`, `evaluators`, `generators`, `harnesses`) includes a `base.py` which defines the base classes usable by plugins in that category. Each plugin module defines plugin classes that inherit from one of the base classes. For example, `garak.generators.openai.OpenAIGenerator` descends from `garak.generators.base.Generator`.\n\nLarger artefacts, like model files and bigger corpora, are kept out of the repository; they can be stored on e.g. Hugging Face Hub and loaded locally by clients using `garak`.\n\n\n## Developing your own plugin\n\n* Take a look at how other plugins do it\n* Inherit from one of the base classes, e.g. `garak.probes.base.TextProbe`\n* Override as little as possible\n* You can test the new code in at least two ways:\n  * Start an interactive Python session\n    * Import the model, e.g. `import garak.probes.mymodule`\n    * Instantiate the plugin, e.g. `p = garak.probes.mymodule.MyProbe()`\n  * Run a scan with test plugins\n    * For probes, try a blank generator and always.Pass detector: `python3 -m garak -m test.Blank -p mymodule -d always.Pass`\n    * For detectors, try a blank generator and a blank probe: `python3 -m garak -m test.Blank -p test.Blank -d mymodule`\n    * For generators, try a blank probe and always.Pass detector: `python3 -m garak -m mymodule -p test.Blank -d always.Pass`\n  * Get `garak` to list all the plugins of the type you're writing, with `--list_probes`, `--list_detectors`, or `--list_generators`\n\n\n## FAQ\n\nWe have an FAQ [here](https://github.com/NVIDIA/garak/blob/main/FAQ.md). Reach out if you have any more questions! [leon@garak.ai](mailto:leon@garak.ai)\n\nCode reference documentation is at [garak.readthedocs.io](https://garak.readthedocs.io/en/latest/).\n\n## Citing garak\n\nYou can read the [garak preprint paper](garak-paper.pdf). If you use garak, please cite us.\n\n```\n@article{garak,\n  title={{garak: A Framework for Security Probing Large Language Models}},\n  author={Leon Derczynski and Erick Galinkin and Jeffrey Martin and Subho Majumdar and Nanna Inie},\n  year={2024},\n  howpublished={\\url{https://garak.ai}}\n}\n```\n\n\u003chr\u003e\n\n_\"Lying is a skill like any other, and if you wish to maintain a level of excellence you have to practice constantly\"_ - Elim\n\nFor updates and news see [@garak_llm](https://twitter.com/garak_llm)\n\n© 2023- Leon Derczynski; Apache license v2, see [LICENSE](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNVIDIA%2Fgarak","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FNVIDIA%2Fgarak","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FNVIDIA%2Fgarak/lists"}