Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 66 additions & 3 deletions doc/scanner/garak.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
"data-exfiltration or cross-site-scripting payloads), a doctor probe (which applies the Policy\n",
"Puppetry universal bypass), system-prompt-extraction probes (which test whether a target can be\n",
"coaxed into revealing its own system prompt), package-hallucination probes (which test whether a\n",
"target recommends non-existent packages that an attacker could squat), an audio probe (which\n",
"delivers spoken jailbreaks to multimodal targets), and FigStep visual jailbreaks (which place\n",
"harmful instructions in images).\n",
"target recommends non-existent packages that an attacker could squat), latent-injection probes\n",
"(which bury instructions inside carrier documents like reports, resumes, and WHOIS records), an\n",
"audio probe (which delivers spoken jailbreaks to multimodal targets), and FigStep visual\n",
"jailbreaks (which place harmful instructions in images).\n",
"\n",
"For full programming details, see the\n",
"[Scenarios Programming Guide](../code/scenarios/0_scenarios.ipynb)."
Expand Down Expand Up @@ -64,6 +65,8 @@
" Encoding,\n",
" EncodingTechnique,\n",
" FigStep,\n",
" LatentInjection,\n",
" LatentInjectionTechnique,\n",
" PackageHallucination,\n",
" PackageHallucinationTechnique,\n",
" SystemPromptExtraction,\n",
Expand Down Expand Up @@ -558,6 +561,66 @@
"await output_scenario_async(web_injection_result)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## LatentInjection\n",
"\n",
"Ports Garak's `latentinjection` probe family: instructions buried inside an otherwise innocuous\n",
"carrier document — translation requests (English to French or Chinese), equity / earnings reports,\n",
"resumes, fact snippets, or WHOIS records. Carrier documents, task instructions, injection\n",
"instructions, payload templates, and expected triggers live in five local datasets; the scenario\n",
"renders their cross-product deterministically (capped per expected trigger) using a\n",
"technique-specific delimiter around the injected instruction. Each expected trigger gets its own\n",
"atomic attack scored with `SubStringScorer`, so success means the target emitted the trigger\n",
"verbatim. The `latent_jailbreak` family instead tries to make the target write harmful content\n",
"about a demographic group under a disguised translation or paraphrase task, and is scored with a\n",
"harm scorer since it has no exact-trigger success contract.\n",
"\n",
"**CLI example:**\n",
"\n",
"```bash\n",
"pyrit_scan run garak.latent_injection --target openai_chat --techniques default\n",
"```\n",
"\n",
"**Available techniques** (14 delimiter styles): Bare, Newline, Blockquote, BlockquoteInline,\n",
"HorizontalRule, SystemTag, SystemBracket, SystemBracketFlood, SystemPrefix, InstructionTag,\n",
"EndOfText, AdminRequest, CoreInstruction, LegalAmendment.\n",
"\n",
"**Aggregate techniques:** `ALL` (all 14) and `DEFAULT` (a representative subset: Bare, Newline,\n",
"Blockquote, HorizontalRule, SystemTag, InstructionTag). Carrier family and language are dataset\n",
"metadata, not techniques; use `carrier_families` (constructor) to narrow the scan."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"latent_injection_scenario = LatentInjection(carrier_families=[\"report\"], max_prompts_per_trigger=2)\n",
"latent_injection_scenario.set_params_from_args( # type: ignore\n",
" args={\n",
" \"objective_target\": objective_target,\n",
" \"scenario_techniques\": [LatentInjectionTechnique.DEFAULT],\n",
" \"include_baseline\": False,\n",
" }\n",
")\n",
"await latent_injection_scenario.initialize_async() # type: ignore\n",
"\n",
"latent_injection_result = await latent_injection_scenario.run_async() # type: ignore"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"await output_scenario_async(latent_injection_result)"
]
},
{
"cell_type": "markdown",
"id": "10",
Expand Down
53 changes: 50 additions & 3 deletions doc/scanner/garak.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
# data-exfiltration or cross-site-scripting payloads), a doctor probe (which applies the Policy
# Puppetry universal bypass), system-prompt-extraction probes (which test whether a target can be
# coaxed into revealing its own system prompt), package-hallucination probes (which test whether a
# target recommends non-existent packages that an attacker could squat), an audio probe (which
# delivers spoken jailbreaks to multimodal targets), and FigStep visual jailbreaks (which place
# harmful instructions in images).
# target recommends non-existent packages that an attacker could squat), latent-injection probes
# (which bury instructions inside carrier documents like reports, resumes, and WHOIS records), an
# audio probe (which delivers spoken jailbreaks to multimodal targets), and FigStep visual
# jailbreaks (which place harmful instructions in images).
#
# For full programming details, see the
# [Scenarios Programming Guide](../code/scenarios/0_scenarios.ipynb).
Expand All @@ -36,6 +37,8 @@
Encoding,
EncodingTechnique,
FigStep,
LatentInjection,
LatentInjectionTechnique,
PackageHallucination,
PackageHallucinationTechnique,
SystemPromptExtraction,
Expand Down Expand Up @@ -178,6 +181,50 @@
# %%
await output_scenario_async(web_injection_result)

# %% [markdown]
# ## LatentInjection
#
# Ports Garak's `latentinjection` probe family: instructions buried inside an otherwise innocuous
# carrier document — translation requests (English to French or Chinese), equity / earnings reports,
# resumes, fact snippets, or WHOIS records. Carrier documents, task instructions, injection
# instructions, payload templates, and expected triggers live in five local datasets; the scenario
# renders their cross-product deterministically (capped per expected trigger) using a
# technique-specific delimiter around the injected instruction. Each expected trigger gets its own
# atomic attack scored with `SubStringScorer`, so success means the target emitted the trigger
# verbatim. The `latent_jailbreak` family instead tries to make the target write harmful content
# about a demographic group under a disguised translation or paraphrase task, and is scored with a
# harm scorer since it has no exact-trigger success contract.
#
# **CLI example:**
#
# ```bash
# pyrit_scan run garak.latent_injection --target openai_chat --techniques default
# ```
#
# **Available techniques** (14 delimiter styles): Bare, Newline, Blockquote, BlockquoteInline,
# HorizontalRule, SystemTag, SystemBracket, SystemBracketFlood, SystemPrefix, InstructionTag,
# EndOfText, AdminRequest, CoreInstruction, LegalAmendment.
#
# **Aggregate techniques:** `ALL` (all 14) and `DEFAULT` (a representative subset: Bare, Newline,
# Blockquote, HorizontalRule, SystemTag, InstructionTag). Carrier family and language are dataset
# metadata, not techniques; use `carrier_families` (constructor) to narrow the scan.

# %%
latent_injection_scenario = LatentInjection(carrier_families=["report"], max_prompts_per_trigger=2)
latent_injection_scenario.set_params_from_args( # type: ignore
args={
"objective_target": objective_target,
"scenario_techniques": [LatentInjectionTechnique.DEFAULT],
"include_baseline": False,
}
)
await latent_injection_scenario.initialize_async() # type: ignore

latent_injection_result = await latent_injection_scenario.run_async() # type: ignore

# %%
await output_scenario_async(latent_injection_result)

# %% [markdown]
# ## Doctor
#
Expand Down
Loading