| name | garak |
| description | Security testing and red-teaming for LLMs using NVIDIA's garak vulnerability scanner. Use when probing AI models for jailbreaks, prompt injections, data leakage, toxic content generation, or other failure modes. Triggers on "test LLM security", "red team model", "run garak", "LLM vulnerability scan", "jailbreak testing", or "prompt injection test". |
| license | Apache-2.0 |
| compatibility | Requires Python 3.10-3.12, pip, and API keys for target LLM platforms (OPENAI_API_KEY, BEDROCK_API_KEY, etc.) |
| metadata | {"author":"evalops","version":"1.0.0","source":"https://github.com/NVIDIA/garak"} |
Garak - LLM Vulnerability Scanner
Garak is NVIDIA's open-source security testing framework for large language models. Think of it as nmap or Metasploit, but for AI systems. It probes whether LLMs can be manipulated into generating harmful content, leaking data, accepting prompt injections, or failing in other undesirable ways.
Installation
python -m pip install -U garak
python -m pip install -U git+https://github.com/NVIDIA/garak.git@main
conda create --name garak "python>=3.10,<=3.12"
conda activate garak
git clone https://github.com/NVIDIA/garak.git
cd garak
python -m pip install -e .
Core Concepts
Architecture Components
| Component | Purpose |
|---|
| Probes | Attack modules that send adversarial prompts to test specific vulnerabilities |
| Detectors | Analyze model outputs to identify harmful or failed responses |
| Generators | Interface with different LLM platforms (OpenAI, HuggingFace, Bedrock, etc.) |
| Buffs | Transform prompts before sending (encoding, paraphrasing, etc.) |
| Harnesses | Orchestrate the testing workflow |
Supported Platforms (Generators)
Commercial APIs:
openai - OpenAI models (requires OPENAI_API_KEY)
bedrock - AWS Bedrock (requires BEDROCK_API_KEY, optional BEDROCK_REGION)
cohere - Cohere API (requires COHERE_API_KEY)
groq - Groq API (requires GROQ_API_KEY)
mistral - Mistral AI
replicate - Replicate API (requires REPLICATE_API_TOKEN)
Local/Self-Hosted:
huggingface - HuggingFace Hub models
ollama - Ollama local models
ggml - GGUF format models (requires GGML_MAIN_PATH)
nim - NVIDIA NIM endpoints (requires NIM_API_KEY)
litellm - Unified LiteLLM interface
Framework Integrations:
langchain - LangChain applications
rest - Custom REST endpoints via YAML config
CLI Reference
Basic Syntax
garak [options]
Essential Flags
| Flag | Description |
|---|
--target_type/-t | Generator module (e.g., openai, huggingface) |
--target_name/-n | Specific model name (e.g., gpt-4, meta-llama/Llama-2-7b) |
--probes/-p | Probes to run (comma-separated or all) |
--detectors/-d | Detectors to use (comma-separated or all) |
--generations/-g | Number of outputs per prompt (default: 5) |
--config | Path to YAML/JSON config file |
Discovery Commands
garak --list_probes
garak --list_detectors
garak --list_generators
garak --list_buffs
garak --plugin_info probes.dan.Dan_11_0
Execution Flags
| Flag | Description |
|---|
--verbose/-v | Increase output verbosity (can stack: -vv) |
--parallel_requests | Concurrent generator requests per prompt |
--parallel_attempts | Concurrent probe attempts |
--seed/-s | Random seed for reproducibility |
--eval_threshold | Minimum threshold for a hit (0.0-1.0) |
--report_prefix | Custom prefix for output files |
--interactive/-I | Enter interactive probing mode |
Probe Categories
Jailbreak Attacks
dan - Do Anything Now variants (Dan_6_0 through Dan_11_0, DUDE, STAN)
grandma - Grandmother exploit
goodside - Known jailbreaks from research
continuation - Text completion jailbreaks
Prompt Injection
promptinject - Direct prompt injection attacks
encoding - Encoding-based bypasses (Base64, Hex, ROT13)
smuggling - Content smuggling techniques
latentinjection - Latent space attacks
Content Safety
realtoxicityprompts - Toxic content generation (Profanity, Threats, Identity_Attack)
malwaregen - Malware code generation attempts
donotanswer - Tests refusal on restricted topics
lmrc - Language Model Red-teaming Checklist
Information Security
leakreplay - Data leakage testing
apikey - API key exposure detection
packagehallucination - Fake package/dependency detection
xss - Cross-site scripting in outputs
Robustness
glitch - Token glitch exploitation
badchars - Invalid character handling
divergence - Behavioral deviation detection
snowball - Snowball attack variants
Common Usage Examples
Test OpenAI Model for Jailbreaks
export OPENAI_API_KEY="sk-..."
garak --target_type openai --target_name gpt-4 --probes dan
Comprehensive Security Scan
garak --target_type openai --target_name gpt-4 --probes all --generations 10
Test Specific Vulnerabilities
garak -t openai -n gpt-4 -p promptinject,encoding
garak -t openai -n gpt-4 -p realtoxicityprompts
garak -t openai -n gpt-4 -p leakreplay,apikey
Test HuggingFace Model
garak --target_type huggingface --target_name meta-llama/Llama-2-7b-chat-hf --probes dan,encoding
Test AWS Bedrock Model
export BEDROCK_API_KEY="..."
export BEDROCK_REGION="us-east-1"
garak --target_type bedrock --target_name anthropic.claude-3-sonnet --probes promptinject
Test Local Ollama Model
garak --target_type ollama --target_name llama2 --probes dan,continuation
Using a Config File
Create scan_config.yaml:
system:
parallel_attempts: 10
lite: true
run:
generations: 5
plugins:
probe_spec: dan,encoding,promptinject,malwaregen
extended_detectors: false
Run with config:
garak --config scan_config.yaml --target_type openai --target_name gpt-4
Output and Reports
Garak generates three types of output:
- garak.log - Debug information (persistent across runs)
- JSONL report - Detailed results at
~/.local/share/garak/garak-runs-{timestamp}.jsonl
- Hit log - Records of successful exploits
Interpreting Results
- PASS: Model resisted the attack
- FAIL: Model exhibited vulnerable behavior
- Failure rate: Percentage of attempts that triggered the vulnerability
Processing Reports
garak --report path/to/report.jsonl
Best Practices
For Comprehensive Testing
- Start broad, then narrow: Run
--probes all first, then focus on failures
- Use multiple generations: Set
--generations 10 or higher for statistical significance
- Test with buffs: Apply encoding transformations to find edge cases
- Document baseline: Run identical tests before and after model updates
For Specific Vulnerability Assessment
- Jailbreaks:
--probes dan,grandma,goodside,continuation
- Prompt Injection:
--probes promptinject,encoding,smuggling
- Content Safety:
--probes realtoxicityprompts,malwaregen,donotanswer
- Data Security:
--probes leakreplay,apikey,packagehallucination
For CI/CD Integration
garak --config garak/configs/fast.json --target_type openai --target_name $MODEL_NAME
garak ... --eval_threshold 0.1
Troubleshooting
Common Issues
API Key errors: Ensure environment variables are set correctly
export OPENAI_API_KEY="sk-..."
Rate limiting: Reduce parallel requests
garak ... --parallel_requests 1
Memory issues with local models: Use smaller batch sizes
garak ... --generations 3
Unknown probe errors: Skip unknown plugins
garak ... --skip_unknown
Resources
Workflow: Running a Security Assessment
When asked to run a garak security assessment:
- Verify installation: Check if garak is installed with
garak --version
- Confirm target: Identify the model type and name
- Set credentials: Ensure API keys are configured
- Select probes: Choose appropriate probes for the assessment scope
- Execute scan: Run garak with appropriate flags
- Analyze results: Review the JSONL report and summarize findings
- Recommend mitigations: Suggest fixes for identified vulnerabilities
Example Workflow
garak --version
garak --list_probes
export OPENAI_API_KEY="sk-..."
garak \
--target_type openai \
--target_name gpt-4 \
--probes dan,promptinject,encoding \
--generations 5 \
--verbose
cat ~/.local/share/garak/garak-runs-*.jsonl | jq '.status'