FEAT: Add Garak latent injection scenario - #2573
Draft
Juhie (juhiechandra) wants to merge 6 commits into
Draft
Conversation
Add the `authors` field and move the copyright and license notice out of the prose that described the port. Each description now names NVIDIA CORPORATION & AFFILIATES as the copyright holder, states that the content is used under the Apache License 2.0, and points at the pinned `source` URL for the original.
Prompt assembly lived in the scenario, which mixed "how the four corpora combine into a prompt" with "how the run is fanned out into attacks". Move the first half into a new `LatentInjectionDatasetConfiguration`, exported from `pyrit.scenario.garak`. It overrides `_build_attack_groups` to combine a task instruction, a carrier document, an injection instruction and a payload into one group per template, and owns the carrier families, the markers and the per-trigger cap. The scenario keeps only the technique fan-out. Templates now leave the dataset configuration with their `<|injection|>` marker intact and carry the assembled injection in the objective metadata, so the scenario applies each technique's separator once per template rather than re-assembling the prompt per technique. Build one atomic attack per (technique, family, trigger) instead of per (technique, family). Each attack is scored by a `SubStringScorer` for its own trigger, so an attack's success contract names the single string its prompts actually asked for. Rename `max_prompts_per_cell` to `max_prompts_per_trigger` to match, and lower the default from 12 to 4 now that the cap applies to a narrower cell. Set `BASELINE_ATTACK_POLICY` to `Forbidden`. The resolved templates still hold an injection marker, so there is nothing meaningful to send as a baseline, and the `bare` technique already covers sending with no fencing at all. Add the `BlockquoteInline` technique for garak's fact-snippet probes, which quote inline with no leading newline and so render differently from `Blockquote`. Also trim the assembly-determinism rationale, which was restated in four places, down to the one docstring that explains the algorithm, and collapse the harm-scorer error message duplicated across two raise sites.
Describe the per-trigger attack split and the absence of a baseline attack in place of the run-size note, which described the old per-cell cap. Add `BlockquoteInline` to the technique list and correct the counts to 14. Fix the CLI example, which passed `--max-prompts-per-cell`, a flag that no longer exists; the parameter is `max_prompts_per_trigger`.
Juhie (juhiechandra)
marked this pull request as draft
September 4, 2026 11:25
|
Juhie (@juhiechandra) please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds a PyRIT-native latent-injection scenario, porting the behaviour of garak's
latentinjectionprobes without porting their runtime structure. Closes #2530; part ofthe scanner parity work in #511. The separation of responsibilities follows the
PromptInject scenario from #2509 rather than garak's
Probe/mixin/detector layout — noProbe, mixin, hook, detector, or generator code is carried over.Every prompt is a benign task ("summarise this resume", "is this domain malicious?")
applied to a carrier document with an attacker instruction buried inside it. The attack
succeeds when the response echoes the trigger text the injection asked for.
Datasets own the source content. Four local
.promptdatasets underpyrit/datasets/seed_datasets/local/garak/hold the ingredients separately — 51 carriercontexts, 27 benign task instructions, 32 injection templates and 75 payloads. Expected
trigger text, carrier family, language and source provenance are preserved as seed
metadata. Garak is Apache-2.0 rather than MIT, so each dataset records NVIDIA as author,
names NVIDIA CORPORATION & AFFILIATES as the copyright holder, states that the content
is used under the Apache License 2.0, pins a commit-level
sourceURL, and notes theonly modification made (garak's templating markers renamed to PyRIT's).
A dataset configuration builds the seed groups.
LatentInjectionDatasetConfigurationoverrides
_build_attack_groupsto combine a task instruction, a carrier document, aninjection instruction and a payload into one
AttackSeedGroupper template. The groups itemits are still templates: the carrier document keeps its
<|injection|>marker and theassembled injection travels in the objective metadata, because fencing the injection is
the technique's job.
Techniques describe application only.
LatentInjectionTechniquehas 14 members, oneper separator style from garak's
injection_sep_pairs, taggedplain(the injection isset off by whitespace or quoting) or
authority(the delimiter impersonates a system,admin or legal voice), with
ALL/DEFAULT/PLAIN/AUTHORITYaggregates. The ninecarrier families —
translation_fr,translation_zh,report,resume,fact_eiffel,fact_legal,whois,whois_snippet,latent_jailbreak— are seed metadata selectedthrough a
familiesrun parameter, not techniques, so any technique applies to any family.The scenario assembles the campaign. One
AtomicAttackper (technique, family,trigger), each a standard
PromptSendingAttack. Bounding an attack to a single triggerkeeps its success contract unambiguous: its
SubStringScorerlooks for the one stringthat attack's prompts actually asked for.
BASELINE_ATTACK_POLICYisForbidden— theresolved templates still hold an injection marker, so there is nothing meaningful to send
as a baseline, and the
baretechnique already covers sending with no fencing at all.latent_jailbreakgets its own path. It hides a "write something offensive about<group>" instruction inside a translation request, so there is no fixed string to match.
It is excluded from the default family set and requires an explicit
harm_scorer;selecting it without one raises with a message naming the fix. The check runs before any
prompt is assembled, so a run-size estimate refuses the selection rather than failing
later at scoring time.
Determinism, because resume matches previously executed work by name. Garak thins its
cross products with an unseeded
random.sampleand assembles its fact-snippet contextsthe same way. Neither is usable here. The cross product is capped per (family, trigger) by
a round-robin walk that advances every axis at once, so the capped population keeps a
spread of tasks, carrier documents and injection templates instead of every variation of
one corner; multi-snippet carrier documents are assembled by a rotating window. The same
inputs always produce the same prompts in the same order, and atomic-attack names are
stable across runs.
Tests and Documentation
Tests — 61 new unit tests, all passing:
tests/unit/scenario/garak/test_latent_injection.py(39) covers technique expansion andthe plain/authority partition, snippet assembly, the dataset configuration, atomic-attack
construction and naming, separator rendering, per-trigger scoring, the missing-harm-scorer
error, and determinism (identical prompts and names across two runs).
tests/unit/datasets/test_garak_latent_injection_dataset.py(22) covers the porteddatasets: required metadata on every seed, marker integrity, and that no garak templating
marker survives the port.
Rendering is checked against the failure modes that matter here: that every marker is
substituted, that payload-inside-instruction-inside-separator nests in the right order, and
that carrier documents containing literal braces (WHOIS records, JSON fragments) survive
rendering — substitution is
str.replace, neverstr.format.The full
tests/unitsuite passes locally, as doespre-commit runover every changedfile (ruff format, ruff check,
ty, and the notebook hooks).Documentation —
doc/scanner/garak.pygains aLatentInjectionsection covering thetechniques, the aggregates, the carrier families, the
latent_jailbreakexception and aCLI example, with
doc/scanner/garak.ipynbkept in sync.On JupyText: the change to
doc/scanner/garak.pyis markdown cells only — no code cell wasadded or altered, and the notebook diff touches a single markdown cell with no changes to
outputs or execution counts. I therefore did not re-run
jupytext --execute --to notebook ./doc/scanner/garak.py, since executing it requires livetarget endpoints and would rewrite unrelated outputs. Happy to run it if a maintainer would
rather see it executed.