Test Local Ollama Models for Prompt Injection with NVIDIA garak 0.17.1 (2026 Guide)
A local model can answer ordinary questions perfectly and still fail when a document, retrieved passage, or adversarial instruction tries to take control of the conversation. You do not need to expose that model to a public red-team service to start checking it. NVIDIA's garak can send controlled probes to a local Ollama model, evaluate the responses with detectors, and save a repeatable record of what happened.
This guide builds a small, deliberately scoped red-team workflow: Ollama serves a local model, garak 0.17.1 connects through its native Ollama generator, and two probe families check direct and context-embedded prompt-injection behavior. You will learn how to keep the scan bounded, read its reports, and compare changes without treating one green result as a security guarantee.
Scope: this walkthrough scans a model endpoint that you own. It does not automatically test every part of a RAG application, MCP server, browser agent, or tool-execution layer. Those components need their own integration tests and authorization checks.
What you will build
The test path is intentionally simple:
garak 0.17.1
|
| selected probes + detectors
v
OllamaGeneratorChat
|
| local HTTP requests
v
Ollama at 127.0.0.1:11434
|
v
Your selected local model
Garak separates probes (the test interactions), generators (the connection to the model), detectors (how results are classified), and the harness that runs the test. The project documents this pipeline in its architecture guide. A detector hit is a signal to investigate the recorded attempt, not proof that a production application has been compromised.
Why garak 0.17.1?
As of 30 November 2026, the latest stable GitHub release and PyPI package listed for garak is 0.17.1, published on 16 October 2026. The release adds a hit@k attack-success metric, shown in terminal output and in the final digest entry of report.jsonl, and adds Python 3.14 support. The repository's development branch can move ahead of the stable release, so this tutorial pins 0.17.1 for reproducibility rather than installing an unpinned development build.
Garak's package metadata requires Python 3.11 or newer. The examples below use Python 3.12, but a compatible 3.11–3.14 interpreter can be used. Always check package resolution on your operating system before standardising a team environment.
Prerequisites
- Ollama installed and running on the same machine as garak, or reachable on a private network you control.
- A chat-capable local model already downloaded in Ollama. The example uses
llama3.2:3b; substitute a model you are authorised to test. - Python 3.11 or newer and pip.
- Enough memory for your selected model. The Ollama library lists the Llama 3.2 3B Q4_K_M artifact at about 2.0 GB; runtime memory also depends on context and concurrent applications.
- A terminal and permission to write scan reports to a local directory.
Step 1: Start Ollama and prepare a model
Confirm that the Ollama CLI is available:
ollama --version
Download the example model and confirm that it appears locally:
ollama pull llama3.2:3b
ollama list
Run a normal chat once so you know the model itself loads before adding another tool to the chain:
ollama run llama3.2:3b
Ask a harmless question, confirm that a response appears, and exit the interactive session. You can also check the local API:
curl http://127.0.0.1:11434/api/tags
Expected result: Ollama responds with a JSON list of local models and the selected model appears in the list. If Ollama is not running as a background service on your platform, start it in a separate terminal with ollama serve.
Step 2: Install a pinned garak environment
Keep the scanner in its own virtual environment so its Python dependencies do not collide with your application:
python3 -m venv .venv
# Linux or macOS
source .venv/bin/activate
# Windows PowerShell
# .venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install "garak==0.17.1"
Check the installed version:
python -m garak --version
Garak 0.17.1 includes an Ollama generator dependency and exposes the generator in its plugin system. The default class for the ollama generator family is OllamaGeneratorChat, which sends chat-style messages to Ollama. The generator's default host is 127.0.0.1:11434 and its default timeout is 30 seconds; we will raise the timeout in the scan configuration below.
Step 3: Inspect the available generators and probes
Before launching a scan, ask the installed version what it can load:
python -m garak --list_generators
python -m garak --list_probes --spec probes.promptinject
python -m garak --list_probes --spec probes.latentinjection
The first command should include the Ollama generator. The other commands show the available probes in the two selected families. This is useful because plugin availability and active status can change between releases.
Choose the right first probes
probes.promptinject: tests direct prompt-injection patterns, including instructions embedded in otherwise ordinary requests. Garak's documentation notes that the family has many possible prompts, so do not begin with an unrestricted full scan.probes.latentinjection: tests instructions embedded inside a larger context, such as a document or retrieved passage. This is relevant to summarisation and RAG-style workflows, but a model-only scan is still not a full RAG integration test.
Garak's unified selector is run.spec (or the CLI --spec flag). Older --probes and --probe_tags flags are deprecated in the current documentation; prefer --spec.
Step 4: Create a bounded scan configuration
Create a file named garak-local.yaml in your working directory:
run:
generations: 1
seed: 42
soft_probe_prompt_cap: 12
spec:
include:
- probes.promptinject
- probes.latentinjection
exclude: []
plugins:
target_type: ollama
target_name: llama3.2:3b
generators:
ollama:
OllamaGeneratorChat:
host: "127.0.0.1:11434"
timeout: 120
max_tokens: 256
reporting:
report_dir: "./garak_runs"
report_prefix: "llama32-local-baseline"
Here is what matters:
target_type: ollamaselects the Ollama generator family. Its default class is the chat generator.target_namemust match the model name shown byollama list.generations: 1keeps the initial run small. Repeat with more generations after you understand the runtime cost.soft_probe_prompt_cap: 12is a preferred cap for probes that can expand their prompt sets. It is a soft limit, not a guaranteed maximum on every plugin or on total model calls.max_tokens: 256is garak's generator parameter; the pinned Ollama generator maps it to Ollama'snum_predictoption.timeout: 120gives slower local hardware more time than the generator's documented 30-second default.report_dirandreport_prefixkeep this run's files grouped and identifiable.
If you use another model, change target_name. If Ollama runs on a different private host, change host to the correct reachable address and protect that connection. Do not expose the unauthenticated local inference endpoint directly to the public internet.
Step 5: Run the first local scan
With Ollama still running, execute:
python -m garak --config garak-local.yaml
Garak should identify the target, load the selected probes and detectors, send requests to the Ollama generator, and print progress and per-probe evaluation. The run will take longer on a CPU-only machine or when the model must be loaded from disk between requests.
For a smaller single-family run, you can override the selector from the command line:
python -m garak --config garak-local.yaml --spec probes.promptinject
Command-line values take precedence over values in the configuration file. Keep the first run narrow; expanding to every active probe can produce a large number of requests and is not a sensible first diagnostic.
Step 6: Find and interpret the reports
Garak prints the paths of the files it creates. Keep those exact paths rather than assuming every installation uses the same generated filename. The project documents three useful outputs:
- Run report: a JSON Lines file containing the scan's attempts and their evaluation records. The final digest includes summary information, including the
hit@kmetric in 0.17.1. - Hit log: a focused record of attempts that produced a detector hit.
garak.log: diagnostic and plugin logging, including errors.
When the terminal marks a probe FAIL, read the corresponding hit record and original attempt. A failure means the selected detector found behavior matching its criterion. It does not automatically mean the entire application is exploitable. Conversely, a PASS means only that the selected prompts and detector did not find a hit in this run; it does not establish that the model is safe.
Review at least these questions for each hit:
- What was the exact input prompt or embedded instruction?
- What did the model return, and did it include the detector's trigger or match?
- Was the result a genuine policy or instruction-boundary failure, or a detector false positive?
- Would the same behavior matter in your application, given its system prompt, retrieved context, tools and permissions?
- Can you reproduce the behavior with the same model tag, configuration and probe selection?
Step 7: Turn a model scan into a useful regression check
A single scan is a baseline, not a security sign-off. Save the configuration alongside the report, record the exact model tag and Ollama version, and rerun the same selection after changing the model, system prompt or surrounding application code.
For a fair comparison:
- Keep the model tag and quantization unchanged while testing a prompt change.
- Keep the probe selection, generation count, prompt cap and detector setup unchanged.
- Record any change to Ollama, garak, GPU runtime or model template.
- Compare the individual hit records, not only a headline pass/fail count.
- Investigate new hits and changed responses manually before turning them into a release gate.
The 0.17.1 hit@k metric is useful as an additional summary, but it is not a universal safety score and should not be compared across different probe sets as if they were identical tests.
Step 8: Extend the test to a RAG or agent application
The native Ollama generator talks to the model endpoint. It does not automatically know how your application retrieves documents, assembles prompts, filters tenant data, or authorises tools. For an application-level assessment, place the test boundary around the application endpoint and use an appropriate garak generator or a separate integration harness. The official REST generator is designed for endpoints that return text or JSON and requires endpoint-specific configuration.
For a RAG system, create a staging corpus containing harmless test documents with clearly labelled, synthetic instructions. Verify that the application treats retrieved text as untrusted data, preserves source boundaries, and does not let document content override the system policy. Then test retrieval filters and tenant isolation separately. Never place real credentials or private customer records in a red-team corpus.
For an agent, test tool authorization independently: a model refusing a prompt is not a substitute for server-side permission checks. A read-only tool layer, explicit allowlists, path validation, scoped credentials and human approval for consequential actions remain important even if the model scan reports no hits.
Troubleshooting
Connection refused at 127.0.0.1:11434
Start Ollama and verify it separately with curl http://127.0.0.1:11434/api/tags. If garak runs inside Docker, remember that 127.0.0.1 points to the container itself, not the host. Use the correct container-network service name or a deliberately configured host gateway.
Model not found
Run ollama list and copy the exact model tag into target_name. If it is missing, pull it again with ollama pull llama3.2:3b. A typo or tag mismatch can look like a generator failure.
Requests time out
Increase the Ollama generator's timeout, reduce the model's context or output budget, and keep generations and the probe cap small. Check whether another process is consuming RAM or VRAM. Garak's Ollama generator is not marked as parallel-capable, so do not assume increasing parallelism will improve local throughput.
The scan is unexpectedly large
Check the active probes with --list_probes and review the run.spec selectors. The default behavior can select all active probes when no explicit spec is supplied. Use a narrow include list and remember that soft_probe_prompt_cap is not a hard global request budget.
Unknown probe or configuration errors
Confirm that the environment is running the pinned version with python -m garak --version. Check the spelling and nesting of the YAML keys, then list the relevant probes. The run log contains plugin and configuration details that are more useful than guessing at a missing module.
Unexpected PASS or FAIL
Read the raw attempt and detector output. Detectors are pattern- or behavior-based and can produce false positives or miss behaviors outside their scope. Change one variable at a time and repeat the same test before drawing conclusions.
Security and privacy checklist
- Only scan models, endpoints and applications you own or have explicit permission to test.
- Keep Ollama bound to loopback for a local-only exercise. Do not publish port 11434 to the internet.
- Use synthetic documents and test data; probes and reports may contain sensitive prompts or model outputs.
- Store report files with restrictive permissions and remove them when they are no longer needed.
- Run agent and RAG tests in a staging environment with no production credentials and no live write-capable tools.
- Do not let a model's refusal behavior act as the only access-control mechanism. Enforce authorization in application code.
- Review the model's own licence and acceptable-use terms before distributing or embedding it in a product.
Frequently asked questions
Does garak work with Ollama without an OpenAI-compatible proxy?
Yes. Garak 0.17.1 includes a native Ollama generator and defaults to its chat class for the Ollama generator family. You can point it at the local Ollama host and a model already installed there.
Does garak test my entire RAG pipeline?
Not when you select the native Ollama generator. That path tests the model endpoint. To assess retrieval, prompt assembly, access filters and application behavior, test the RAG application boundary with an appropriate endpoint generator and separate integration checks.
Should I run every probe?
Not for a first pass. The project warns that even a subset of PromptInject probes can create many requests. Start with a narrow, capped selection, inspect the results, and expand deliberately.
Does PASS mean my model is secure?
No. It means the selected probes and detectors did not find a matching issue during that run. Coverage is finite, model behavior can vary, and application-level vulnerabilities may sit outside the model endpoint.
Can I use garak in CI?
Yes, as one component of a controlled evaluation workflow. Pin the scanner and model, keep the probe set bounded, retain JSONL and hit logs as artifacts, and have a review process for detector hits. Do not assume a generic exit code or one aggregate metric is a complete release decision without validating it in your own pipeline.
Official documentation and source links
- NVIDIA garak v0.17.1 release notes — stable release changes, hit@k and Python 3.14 support.
- garak 0.17.1 on PyPI — package metadata, Python requirement and release files.
- garak v0.17.1 source tree — version-pinned source code.
- Ollama generator reference — host, timeout, model and generator parameters.
- garak configuration reference — YAML configuration and unified probe selection.
- garak CLI reference — target, spec, report and generator options.
- PromptInject probe reference — direct prompt-injection tests.
- Latent injection probe reference — instructions embedded in larger contexts.
- Ollama Llama 3.2 3B model page — example model tag and artifact details.
- Ollama documentation — installation and local API reference.
Related GyanAangan guides
- Regression-test local LLMs with Promptfoo and Ollama — complementary functional and prompt regression testing.
- AI agent security: prompt injection, permissions and sandboxing — broader threat-model context.
- Multi-tenant RAG security — retrieval isolation and tenant boundaries.
- Build a safe read-only Ollama codebase agent — tool allowlists and local agent safeguards.
- Run Ollama in Docker with an NVIDIA GPU — container deployment and troubleshooting.
- RAG evaluation with Ragas, DeepEval and Phoenix — evaluate retrieval and answer quality separately.
Bottom line: garak gives local-model developers a repeatable way to probe selected failure modes without sending model prompts to a hosted scanner. Keep the first run small, inspect every hit, and treat the output as evidence for a broader security review—not as a certificate that a model or application is safe.
