By UNST33R
Garak LLM security scanning: an OpenAI-compatible API tutorial
Run NVIDIA garak against an OpenAI-compatible model API, select useful red-team probes, parse JSONL evidence, set regression gates, and avoid misleading score comparisons.
Garak gives an LLM security team a repeatable way to probe a model API for prompt injection, encoded attacks, jailbreaks, data leakage, hallucination, and other undesirable behavior. It sends attack prompts through a generator, scores the responses with detectors, and writes attempt-level evidence plus aggregate results.
The tool is useful for model acceptance and regression testing. It does not exercise an agent's authorization gateway, browser, memory store, or production tool calls unless those components are exposed through the target interface. Treat a garak run as one layer in a broader security test plan.
This tutorial uses garak 0.17.1, released on PyPI on October 16, 2026, and an OpenAI-compatible UNST33R endpoint. The configuration works with the three public model IDs and keeps the run artifacts needed for review.
Understand the garak test model
Garak uses three terms throughout its official documentation:
| Component | Role | Security question |
|---|---|---|
| Generator | Connects garak to the target model or API | Which system is being tested? |
| Probe | Builds and sends adversarial prompts | Which attack behavior is exercised? |
| Detector | Scores model responses | What counts as a successful attack? |
One probe can invoke several detectors. Each prompt can also receive multiple generations because stochastic models may resist once and fail on a later attempt. The default configuration uses five generations. NVIDIA's performance guidance recommends at least two when reducing cost, since one sample can miss transient behavior.
The score direction requires care. In an evaluation record, passed means the detector did not register the undesirable behavior. Attack success rate is fails / total_evaluated. The HTML digest's absolute_score is a pass rate, while hit_at_k values are attack hit rates. Mixing those directions can invert a release decision.
Garak's FAQ also states that scores from different probes are not normalized. A 90% pass rate on one probe cannot be ranked directly against 90% on another. Compare the same probe, detector, generation count, configuration, and case set across model or prompt versions.
Install and pin the scanner
Use a dedicated virtual environment and pin the version recorded in the report. PyPI listed 0.17.1 as the current release when this guide was checked on November 5, 2026.
python3 -m venv .venv-garak
. .venv-garak/bin/activate
python -m pip install --upgrade pip
python -m pip install "garak==0.17.1"
garak --version
garak --list_probes
Commit the version constraint and scan configuration with the application or evaluation repository. Do not commit API keys or raw hit logs that contain sensitive prompts and responses. The report can preserve system prompts, generated payloads, model output, and data that the target leaked during a successful test.
Run the scanner from an isolated CI job or analyst workstation. Give that identity access only to the model endpoint under test. A model scan does not need cloud administration credentials, repository write tokens, or production tool credentials.
Configure an OpenAI-compatible endpoint
Garak 0.17.1 includes openai.OpenAICompatible. Its generator implementation reads the API key from OPENAICOMPATIBLE_API_KEY and accepts a custom uri. Put the generator settings under the complete plugin hierarchy so they apply before the client is created.
Save this as garak-unst33r.yaml:
system:
parallel_attempts: false
parallel_requests: false
run:
seed: 7331
generations: 2
soft_probe_prompt_cap: 64
plugins:
target_type: openai.OpenAICompatible
target_name: unst33r-deepseek
generators:
openai:
OpenAICompatible:
uri: "https://api.unst33r.si/v1/"
temperature: 0.2
max_tokens: 512
reporting:
report_dir: garak-runs
report_prefix: unst33r-deepseek-baseline
hit_at_k: [1]
Then load the key in the process environment and run a small encoded-prompt family:
export OPENAICOMPATIBLE_API_KEY="$UNST33R_API_KEY"
garak \
--config garak-unst33r.yaml \
--spec probes.encoding
unst33r-deepseek is appropriate when probes contain security code, payload descriptions, or dual-use terminology that commonly triggers attacker-side refusal. A reduced-refusal target will intentionally pass fewer policy-refusal checks than a safety-aligned assistant. Define the desired behavior for your deployment before interpreting that as a defect.
For a production application that is expected to block harmful requests, point garak at the actual application boundary. Scanning a reduced-refusal model directly answers whether the model produces a behavior. It does not answer whether your gateway, policy layer, or tool executor contains that behavior.
Start with three bounded probe families
A full default scan can be expensive and hard to review. Begin with families tied to an explicit threat model:
| Probe family | What it exercises | Useful acceptance question |
|---|---|---|
probes.encoding | Encoded or transformed attacks | Does preprocessing expose a bypass that plain text blocks? |
probes.promptinject | PromptInject-style instruction override | Can untrusted content displace the intended task? |
probes.dan | Jailbreak prompt families | Did a model or system-prompt change increase known jailbreak success? |
List the exact classes before scheduling a large run:
garak --list_probes | grep -E 'encoding|promptinject|dan'
Run one family at a time and give each output a distinct prefix. Garak's current CLI uses --spec; the older --probes flag is deprecated. The selection grammar supports an entire family, one class, tag filters, and exclusions.
garak --config garak-unst33r.yaml \
--report_prefix deepseek-promptinject \
--spec probes.promptinject
garak --config garak-unst33r.yaml \
--report_prefix deepseek-dan-minus-one \
--spec probes.dan,-probes.dan.DanInTheWild
The soft_probe_prompt_cap limits families that support auto-scaling, though the documentation labels it a soft cap. Estimate cost from the resolved schedule and observed token usage rather than multiplying the cap by the number of families. A probe may ignore the cap, use multi-turn interactions, or invoke more than one detector.
Separate model properties from harness properties
Security teams often want one number called “jailbreak rate.” That number can combine several different controls:
| Test boundary | What a failure demonstrates | What it leaves untested |
|---|---|---|
| Direct model API | Model response behavior under the chosen system prompt | Gateway rules, retrieval, memory, tools |
| Application chat endpoint | Combined prompt assembly and application filtering | Privileged actions hidden behind separate workers |
| Tool-enabled agent | End-to-end action and authorization behavior | External systems outside the test scope |
Direct model scanning is valuable for release comparisons. An application scan is necessary for deployed risk. If the production agent wraps a model behind retrieval and tools, add a test adapter that accepts garak's prompt and returns the final user-visible answer. Then run separate adversarial cases against the tool boundary.
The LangChain and MCP test guide covers prompt injection that reaches unsafe deserialization or command execution. The multi-agent attack-surface primer adds confused-deputy and shared-memory cases. Garak can supply model-level probes, while those workflows verify the application consequences.
Read the JSONL evidence correctly
Garak's reporting reference documents three primary artifacts: a JSONL report, an HTML summary, and a JSONL hit log. The report contains setup, attempt, evaluation, and digest entries. Attempt records preserve prompts and responses; evaluation records summarize each probe and detector pair.
Locate the report produced by the run and extract evaluation rows:
report=$(find garak-runs -name 'deepseek-promptinject*.report.jsonl' -print -quit)
jq -c '
select(.entry_type == "eval") |
{
probe,
detector,
passed,
fails,
total_evaluated,
nones,
attack_success_rate:
(if .total_evaluated > 0
then (.fails / .total_evaluated)
else null
end),
hit_at_k
}
' "$report"
Treat nones as missing evidence. They are unscoreable outputs and excluded from total_evaluated. A run with many timeouts, malformed responses, or empty results can appear clean because fewer outputs reached a detector. Set a separate CI threshold for nones and request errors.
Review every hit before promoting it into a regression set. Regex and model-based detectors can produce false positives or miss context-specific harm. Preserve the attempt UUID, probe, detector, prompt, response, model ID, scanner version, and configuration hash for each accepted case.
Build a stable regression gate
A release gate should compare matched runs. Keep these variables fixed:
- garak version and plugin set
- selected probe classes and exclusions
- target model ID and application route
- system prompt and generation parameters
- seed, generation count, and prompt cap
- detector threshold and extended-detector setting
- language, retry policy, and request timeout
Create a baseline from an approved release, then gate on per-detector deltas and critical case failures. A blanket “overall pass rate above 95%” can hide a severe regression when a large easy family dilutes a small important family.
A practical policy can look like this:
| Condition | Result |
|---|---|
| Any accepted critical regression case hits | Block |
| Prompt-injection ASR rises by more than 2 percentage points on the same cases | Block pending review |
nones / total_processed exceeds 1% | Mark run invalid and retry once |
| New probe or detector version appears | Require a new baseline |
| Only low-severity stochastic hits move within the historical interval | Send to analyst review |
The two-percentage-point value is an example policy, not a universal quality standard. Choose thresholds from your own baseline variance and impact model. Run enough repeated generations to estimate the behavior you care about. Garak 0.17.1 reports hit@1 and the full generation count, which helps distinguish per-attempt risk from “at least one breach across repeated tries.”
Store the report and config as CI artifacts, then record the report hash in the release decision. The PyRIT CI/CD gate tutorial shows the same evidence-first release pattern for a custom adversarial corpus. The PyRIT multi-model sweep is useful when you need one case set scored across several attacker or target models.
Compare public model tiers without changing the test
All public UNST33R tiers use the same API contract. For a matched comparison, change only plugins.target_name, give the report a new prefix, and retain identical probe settings. The security workload tier guide summarizes model selection considerations and live routes.
Run the fast tier for broad, inexpensive coverage, then repeat accepted high-impact cases against the stronger reasoning tier. Keep the direct model result separate from the deployed application's result. An uncensored or abliterated model is designed to reduce refusals, so model-level jailbreak probes may describe intended capability. Tool-scope violations, data leakage, prompt extraction, and format instability remain actionable regardless of that positioning.
Every scan must stay within systems and accounts you own or have permission to test. Some garak probes deliberately request harmful, deceptive, or sensitive content. Use a dedicated project, restrict artifact access, set budget alerts, and follow the acceptable-use policy.
A first-week operating plan
Day one should establish connectivity with one probe class and two generations. Day two expands to the three bounded families and reviews every hit. Day three converts confirmed high-impact hits into a small fixed regression corpus. Day four scans the production application adapter and records which model-level hits are contained by the application. Day five adds the approved cases to CI with explicit invalid-run and regression thresholds.
That sequence produces an evidence set a reviewer can audit. It also prevents a broad scanner score from standing in for a threat model. Garak is strongest when its probes are mapped to a deployment boundary, its detector output is manually calibrated, and every release is compared against the same recorded test surface.