Encoding-based prompt injection testing with garak: when your model decodes hidden instructions
Encoding probes test whether a model will decode a hidden instruction and then act on it, which matters when your input filters, keyword rules or moderation layer only read plain text. A team needs these probes when the application passes user content to a model that can read Base64, hex, ROT13, Morse or Unicode tag characters, because a request that a filter would block in English can arrive disguised and still be understood by the model. The question is not whether the model is capable of decoding, since most capable models are, but whether its refusal behavior and tool permissions still hold once it has decoded the text.
garak, the Generative AI Red-teaming and Assessment Kit, is an open-source command-line scanner from the NVIDIA GitHub organization that is licensed under Apache 2.0. Its encoding module, in the source file probes/encoding.py, includes injection probes for Base64, Base16, Base32, Ascii85, hex, quoted-printable, UUencode, MIME, ROT13, Base2048, Braille, Atbash, Morse, NATO, Ecoji, Zalgo, leetspeak, Unicode tag characters, Unicode variant selectors and SneakyBits. Each family wraps an instruction in a different encoding and asks the target to decode and follow it, so one scan can show which schemes the model reads and which of them change its behavior. Before you rely on any result, confirm the probe list against the version you install, since the module changes between releases.
For a practical starting point, pick the encodings that match your application's real exposure: for example, Base64 and hex if users paste payloads or code, Unicode tag characters if content arrives from web pages or documents, and ROT13 or Morse only as low-cost checks of model compliance. Confirm which generator settings, system prompt and tools your staging endpoint uses, because a decoded instruction that reaches a tool with write access is a more serious finding than one that produces only a text answer. Plan to record the probe family, the decoded instruction and the model reply for every failure, so that the failure can be reproduced after a model or prompt change.
Which encoding families garak tests and what each one exposes
What standard encodings does garak test for prompt injection?
garak's encoding probes include standard byte-to-text encodings: Base64, Base16, Base32, Ascii85, hex, quoted-printable, UUencode and MIME. A model that decodes these without being asked is treating the encoded text as instructions it can act on. The exposure matters most for applications that accept user content, fetch web pages, read email or parse attachments, because those inputs may carry encoded text that bypasses filters looking for plain-language attacks. To check whether this matters for your model, confirm which of these encodings it recognizes in practice, since decoding ability varies by model size and training. Your application may also decode content in a pipeline step before the model sees it, so test the full path, not only the bare model.
Why do ROT13, Atbash and leetspeak matter for a model?
These are text ciphers and character substitutions. ROT13 and Atbash shift or mirror letters, so a model must recognize the substitution pattern and reconstruct the original words. Leetspeak replaces letters with digits and symbols, which many models read easily, so it tests whether filters and the model itself treat altered spellings as the same request. These probes expose gaps where a guardrail matches exact keywords but the model still understands the meaning. They are useful when your application relies on keyword blocklists or when users can write in informal or disguised text. Confirm with your model vendor how it handles ciphered text in your supported languages before drawing conclusions from a scan.
How do Morse, Braille and NATO alphabet encodings differ from standard encodings?
These are symbolic and visual forms. Morse uses dots and dashes, Braille uses Unicode braille characters, and the NATO phonetic alphabet spells words as code words. A model must map each symbol to a letter, then assemble the letters into words, which is a multi-step interpretation task. Results depend heavily on whether the model was exposed to such forms during training, so a failure may reflect limited capability rather than a safety control working. Read these results as a signal of what the model can interpret and whether your input filters or output checks would see the meaning. Ask your model provider which symbolic formats it documents as supported.
What does Ecoji and Base2048 encoding test?
Ecoji and Base2048 map binary data onto sets of emoji or other Unicode symbols, so the payload looks like ordinary characters. The model must recognize the symbol table and decode the sequence, which is harder than standard Base64 for most models. These probes matter for applications that display or log model input and output, because symbol-based payloads can pass through text pipelines that were built for ASCII. They also test whether your content moderation handles non-Latin Unicode blocks. Confirm with your logging and moderation vendors whether they normalize or inspect emoji-range and extended Unicode text.
What do Zalgo and Unicode variant selectors test?
Zalgo text stacks combining diacritics on characters, and Unicode variant selectors attach invisible modifiers to base characters. Both produce text that looks garbled or is invisible to a reader, while the underlying characters remain readable to a model. The risk is that a human reviewer or a simple filter sees harmless text while the model reads a hidden instruction. These probes matter for review queues, support tooling and any workflow where people approve model output by eye. Check whether your input normalization strips combining marks and variant selectors before text reaches the model or a guardrail.
What are Unicode tag characters and SneakyBits, and why test them?
Unicode tag characters live in a block that mirrors ASCII but is normally invisible in display, and SneakyBits encodes bits using invisible Unicode characters. A model may decode the hidden text while the user, reviewer or log viewer sees nothing unusual. Testing these forms checks whether your application strips, rejects or flags invisible characters at ingestion and at output. This is a common gap in chat interfaces, copy and paste flows and document parsers. Ask your engineers whether the stack sanitizes these code points in prompts, retrieved documents and tool outputs, and whether the sanitization is tested.
How should I choose which encoding families to run first?
Start from the way your application receives text. A chatbot that only accepts typed input has a different exposure from a RAG system that ingests web pages, PDFs and email. Prioritize standard encodings and invisible Unicode forms when your pipeline fetches external content, and symbolic forms when humans review output by eye. Run a small set first, read the detector results for each family, and then expand only where the application path makes the encoding plausible. Document the chosen families and the reason for each, because a scan report without that context is hard to defend in a security review. Your team should confirm the exact probe names in the garak version you install, since probe lists change between releases.
Which encodings matter for a given model
This table compares encoding groups from garak's encoding module against traits you can check in your own environment: multilingual ability, tokenizer behavior, Unicode tag rendering and tool-call parsing. Read each row as a condition to verify, not a fixed result, because model behavior varies by version and deployment. Most teams find the highest-value encodings are the ones their model can decode and their application can pass through unchanged.
| Encoding group | Model or app trait that raises priority | When the probe is low priority |
|---|---|---|
| Base64, Base32, Base16 and hex | The model reliably decodes these strings in testing, or a tool or code path decodes them before acting | The model shows no decoding ability on short samples, so a failure would mostly reflect confusion, not bypass |
| ROT13, Atbash and leetspeak | The model follows simple letter substitutions in your languages, which suggests it can reconstruct plain text from them | The model answers these inputs as gibberish and the application never reads substituted text |
| Morse, Braille and NATO phonetic | The model handles symbol or word-level ciphers and your users or integrations send such inputs | The model cannot map these symbols to words in a quick check, so decoding would be unlikely |
| Unicode tag characters and variant selectors | The app or its renderer passes invisible tag characters through to the model, or copies user text into prompts unchanged | The input path strips or rejects these code points before the model receives them |
| SneakyBits, Zalgo and Ecoji | Your tokenizer splits these forms into many tokens, and the model still reads the underlying text in your check | The model fails to reconstruct text, so results would mostly show noise rather than instruction following |
| Ascii85, UUencode, quoted-printable and MIME | The model or a downstream tool parses email, attachment or legacy text formats in your workflows | No part of your application handles these formats and the model has no reason to decode them |
| Multilingual encodings combined with translation | Your model is deployed for languages where its safety tuning is thinner, so confirm behavior per language | Your model and users operate in one language with strong, tested coverage in that language |
| Tool-calling and parsing paths | A tool call parses decoded text, runs code or writes files based on model output, which turns a decoding success into an action | The model has no tools and its output only reaches a human reader who sees the same text |
Running encoding probes in your environment
This sequence takes you from a clean Python environment to a finished encoding-probe run with a readable JSONL report and debugging log. Each step ends with a check so that a configuration error is caught before it costs a full scan.
Confirm the Python version and create an environment
Check that the host runs Python 3.11 or newer, since the PyPI package requires it, and create a dedicated virtual environment for garak so its dependencies stay separate from the rest of your tooling. Your platform team or the engineer running the scan does this on a host that can reach the target model. You are done when the interpreter reports version 3.11 or higher inside the new environment.
Install garak from PyPI
Install the package with pip inside the activated environment, then confirm the command-line entry point is available. Record the installed version so the report can be matched to the exact release later. Note that garak is developed on Linux and macOS, so a Windows host should be checked against the user guide before you rely on it. The step is complete when the garak help output prints and the version is written into your scan notes.
Connect the target through a generator
Choose the generator that matches your model. garak supports Hugging Face Hub, Replicate, OpenAI, AWS Bedrock, LiteLLM, llama.cpp and REST endpoints. For an internal application, create a short YAML file describing the REST endpoint, including the URL, request body shape and how to read plaintext or JSON responses. Store any API keys in environment variables rather than in the file. Confirm exact configuration keys in the garak user guide for your version.
Verify the generator responds before scanning
Run a single short prompt through the generator before any probe runs. A small test, such as asking the target for a one-line answer, shows whether authentication, routing and response parsing work. If the endpoint returns an error, an empty body or a response in an unexpected format, fix the generator configuration now. The check passes when you see a sensible text reply that garak can read.
Select the encoding probes by name
Choose the encoding probe family for the scan, either by naming individual probes or by selecting the encoding module, and keep the list explicit so the run can be repeated. Encoding probes cover schemes such as Base64, hex, ROT13, Morse and Unicode tag characters, and you should pick the schemes that match what your application actually decodes or passes through. List the chosen probe names in your scan notes. The selection is ready when garak lists the probes and their count before execution.
Run the scan with default generations
Start the scan with the default settings, which make 5 generations per prompt and use each probe's recommended detectors. Keep the generation count at its default for the first run so that results are comparable with later runs. Watch the console for errors from the generator, since a failing endpoint can produce misleading results. The run is finished when garak reports completion and prints a summary for each probe.
Inspect the JSONL report and garak.log
Open the JSONL report written for the run, which records each attempt, its output and its evaluation, and check that the number of attempts matches the probes and generations you configured. Then read garak.log for generator errors, retries or detector warnings, since the log continues across runs and should be checked for the current run's timestamps. A probe marked FAIL means at least one attempt produced undesirable output, so review those attempts before drawing conclusions. The step is complete when every probe has a reviewed set of attempts and no unexplained errors remain.
How to read decoding-based failures in the report
A garak probe is marked FAIL when any of its default five generations per prompt produces undesirable output, so one bad attempt out of five is enough to fail the probe. The failure rate reported alongside it tells you how often that happened across all attempts. Read the two together: a low rate on a probe that fails once still deserves a look at the one attempt, while a high rate on a probe with many encodings points to a broad weakness rather than one lucky payload. Do not set a pass threshold from the rate alone until you have agreed one with the owner of the application, because garak does not decide what is acceptable for your risk.
Start from the JSONL report, which records every attempt along with its evaluation. For each failed attempt, find the exact prompt sent, confirm which encoding was applied, and decode the payload yourself to see what instruction the model was given. Then read the model's response. A model that decodes the instruction and says it cannot comply has shown comprehension, which is a different finding from one that carries out the hidden task. Keep the decoded text, the response and the detector name together in your notes so a reviewer can follow the chain without rerunning the scan. The garak.log file helps when an attempt errored rather than returning a response, since an error is not evidence of compliance.
Detectors can score a response as failed when it is not a real compliance event, for example when the output repeats the decoded text back, quotes the instruction while refusing, or contains a string that matches a pattern by accident. Check a sample of flagged responses by hand before reporting a finding, and note each false positive so it can be excluded from the count. Confirm with the detector documentation in the garak user guide which detector scores each encoding probe in the version you run, because detector behavior can change between releases. Report confirmed compliance separately from detector noise so the result stands up to review.
Security and operational considerations for encoding scans
An encoding scan produces decoded attack payloads, model outputs and logs that can be sensitive in their own right. The cards below cover what to protect, where traffic and credentials may go, and when a scan needs sign-off before it touches anything live.
Treat garak.log and reports as sensitive
Each run writes a JSONL report of every attempt and its evaluation, and garak.log is continued across runs. Together they hold the encoded prompts, the model's decoded replies and any content the model produced under pressure. Restrict read access to the scan team, keep these files out of shared drives and general log pipelines, and confirm with your security team how long they may be retained before you start scanning.
garak READMEKeep scan traffic on approved endpoints
garak sends prompts to whatever generator you configure, including hosted APIs, Hugging Face Hub models and any REST endpoint. Before a run, list every destination the configuration can reach and confirm each one is approved for test traffic that contains harmful-looking content. A misspelled host in a REST generator file is a common way test payloads leave the approved boundary.
Handle credentials for hosted generators
Hosted generators such as OpenAI API models and AWS Bedrock models need API keys or cloud credentials. Keep them in your secrets manager or environment variables rather than in YAML files committed to a repository. Use a dedicated test key with a spending limit and rotate it after the engagement, so a leaked scan configuration does not expose a production account.
Plan storage for encoded test payloads
Encoding probes store their payloads in encoded forms such as Base64, hex, ROT13 and Unicode tag characters, so simple keyword search on reports can miss them. Decide where the payload set lives, who may change it, and how it is versioned in Git. Ask whether the payloads themselves are sensitive under your policies, since a reviewer may need to reproduce a finding exactly.
Get approval before testing live users
Run encoding probes against a staging or pre-production copy of the application whenever possible. Pointing a scan at production can expose real customers to unusual outputs and can trigger rate limits or abuse controls that affect them. If a live test is unavoidable, agree the window, the endpoint, the request budget and a stop condition in writing with the application owner before the first request is sent.
How an encoding probe travels from prompt to verdict
The run starts on the garak host, where the encoding probe wraps each test instruction in a chosen scheme such as Base64 or ROT13. The generator then crosses the trust boundary and sends the encoded prompt to the target endpoint, and the model's output returns along the same path. Back on the garak host, the detector and evaluator score each attempt, and the report records every attempt and its FAIL status. Check what crosses the boundary, since the encoded text is what the model sees.
Encoding probe flow from payload construction to the recorded verdict, across the trust boundary.
Questions teams ask before running encoding tests
Is garak free to use under the Apache 2.0 license?
Yes. garak is licensed under Apache 2.0 and is developed in the NVIDIA GitHub organization, and the maintainers describe it as a free tool. The license cost is zero, so your spend is the people who run and interpret scans, the model endpoints you test against, and any compute you add. Confirm the license terms in the garak README with your legal team before you adopt it, and review the license file for any redistribution you plan, such as bundling garak into a product.
How much does an encoding test cost to run?
The tool itself costs nothing, so the cost comes from three things: engineer time to set up the target and read results, the inference bill for every generated prompt, and any hosting for the endpoint you test. Encoding probes send many prompts, and garak makes 5 generations per prompt by default, so a broad encoding sweep multiplies quickly on a paid API. Ask any partner for a quote that separates one-time setup from recurring scan runs and lists the model calls your scan plan assumes.
How long does an encoding test take?
Duration depends on the number of encodings selected, the number of generations per prompt, the speed of your endpoint and any rate limits it enforces. A local model and a hosted API will behave differently, so run a small pilot against a few encodings first and measure how long it takes. The larger time cost is usually analysis: deciding whether a decoded response is a real failure, a refusal or a false positive takes review by someone who knows the application. Plan that review time explicitly.
Can our own team run garak encoding probes?
Yes, if you have people who can install a Python tool, write a short YAML endpoint configuration for garak's REST generator, and interpret results. garak is a command-line tool installed from PyPI with pip, and the package requires Python 3.11 or newer. The skills gap is less about running the command and more about deciding which encodings matter for your model and reading decoding-based failures correctly. Confirm that your hosts run Linux or macOS, the platforms garak is developed on, before you start.
What does the team need to provide for an encoding scan?
The scan needs access to the target, which is the model or application endpoint, plus the request and response format so garak can talk to it. Your team should provide:
- A test endpoint or staging environment that matches production behavior and guardrails
- Credentials with rate limits and cost limits agreed in advance
- The system prompt and tool settings the application uses, if the scan must reflect them
- A named reviewer who knows the application's intended behavior and can judge decoded output
- A place to store the JSONL report and garak.log for later comparison
How do we choose which encodings to test for a model?
Start from exposure rather than running every encoding. Ask whether the model can decode the scheme at all, since a model that cannot read Morse or Braille will not follow an instruction hidden in it, and whether the application passes user input through decoders, parsers or tools that might. Text-friendly schemes such as Base64, hex and ROT13 matter for most chat and document workflows, while Unicode tag characters and variant selectors matter when input filters only inspect visible text. Confirm your choices with the model provider's documentation and your own pipeline before you finalize the probe list.
When should we bring in outside help for encoding tests?
Bring in outside help when the results will serve as evidence for a customer, an auditor or a release gate, or when the application has tools, retrieval or agents that can act on decoded instructions. An outside team can also help when your staff lack time to triage findings or to build the endpoint integration. DeployOpen plans, runs and documents security testing, including AI and agent security, and works on fixed-scope engagements agreed in writing before work starts. Ask any provider to define the scope, deliverables and retest approach in writing.
How do we interpret a decoding-based failure?
A failure means the model produced undesirable output in at least one attempt, which garak marks as FAIL with a failure rate. Decoding-based failures often come from the model following a hidden instruction after decoding it, so check whether the response actually carried out the instruction or only mentioned the encoded text. Review the attempt in the JSONL report, compare it with the detector result, and record whether a guardrail or the model itself produced the outcome. Re-run the same probe after any change to the model or guardrail so results stay comparable.
Official garak sources for encoding probes
The authoritative list of encoding probes is the source file probes/encoding.py in the NVIDIA garak repository. Check the class names, payload definitions and any detector pairings there before you write a scan plan, because the encodings a probe family covers are defined in that file and not in a summary page. Record the garak version you tested against, since the module can change between releases, and confirm the exact probe names with garak --list_probes on your installed version. Treat any encoding named in this page or in marketing material as a starting point to verify against the source rather than a fixed inventory.
For everything outside the probe definitions, the README and the user guide are the next reads. The garak README on GitHub covers installation, the default probewise harness and the JSONL report written for each run. The garak user guide documents generator configuration, including the REST generator's YAML file that describes your endpoint, and the options that control generations per prompt and report output. Use these pages to set up the target that your encoding probes will reach, since a probe that cannot reach a faithful copy of your production prompt path produces results that do not transfer. Confirm each setting against the version you run, because the guide and README track the current release line.
Keep a short internal record that links each probe you run to the source line that defines it, the garak version and the generator configuration used. When a result is challenged by a security reviewer or an auditor, that record shows what was tested and how, and lets your team rerun the same probe after an upgrade. Ask the team that owns the target application to confirm which generator path, system prompt and guardrail layers are active during the scan, because the source file does not describe your deployment. Where the documentation and the source disagree, trust the source for probe behavior and raise the discrepancy with the maintainers through the project's repository.
How DeployOpen scopes and delivers encoding-based testing
DeployOpen plans and runs encoding-based prompt injection testing with garak as part of a written, fixed-scope engagement. The work covers which encodings match your model and application, how the scan is built and run in infrastructure you control, and how failures are documented and retested.
How we scope
- Written scope names the target model or application, its endpoints and the encodings to be tested with garak.
- Scope records which probes and detectors apply, based on how user input reaches the model and where output is used.
- Engagements are fixed-scope, with deliverables and timelines agreed in writing before any scan begins.
How we build
- Scan environment is set up with garak installed from PyPI on Python 3.11 or newer, in your own infrastructure.
- Generator configuration connects garak to your REST endpoint or model service through a short YAML file.
- Scans run the encoding probes with recommended detectors, and each run's JSONL report and garak.log are kept as evidence.
How we hand over
- Findings report maps each failed encoding to the decoding behavior that caused it, with reproduction steps.
- Recommended fixes cover input normalization, output filtering and system prompt handling, agreed with your engineers.
- Handover includes the scan configuration, reports and a retest after fixes so your team can rerun the same scan.
How we support
- Ongoing support, upgrades and continuous testing are available as retainers for teams that rescan after model changes.
- Retesting after each fix confirms whether a failure was resolved or only shifted to another encoding.
- Ask your DeployOpen contact to confirm the garak version to be pinned, since results can shift between releases.

