garak icon indicating copy to clipboard operation
garak copied to clipboard

promptinject: capped probes apply settings from the wrong prompt

Open reeve25 opened this issue 2 months ago • 0 comments

Steps to reproduce

from garak import _config, _plugins
_config.load_base_config()
p = _plugins.load_plugin("probes.promptinject.HijackHateHumans")
print(sum(p.pi_prompts[i]["prompt"] != p.prompts[i] for i in range(len(p.prompts))))
# 255

load_data_all_attacks shuffles and truncates self.prompts when the prompt cap applies, but leaves self.pi_prompts in its original order. _attempt_prestore_hook and _generator_precall_hook both read self.pi_prompts[seq], so on the capped probes (HijackHateHumans, HijackKillHumans, HijackLongPrompt) attempts get another prompt's settings.

Expected behavior

Each attempt's settings come from the same PromptInject entry as its prompt.

Current behavior

With the default cap of 256, 255 of 256 attempts are mismatched:

  • the generator gets the temperature, top_p and max_tokens meant for a different prompt
  • notes["settings"] in the report records the wrong base prompt, attack instruction and config

Triggers aren't affected since the rogue string is the same within each class, so detector results look normal, which is probably why this hasn't come up. The *Full variants are fine.

Possible fix: shuffle and truncate self.pi_prompts, then build self.prompts from it. Same selection for a given seed. I have a small patch with a regression test and can open a PR.

garak version

main @ 8d1259ef

Additional Information

  1. Windows 11
  2. Python 3.12
  3. Direct repository checkout with git

reeve25 avatar Oct 01 '26 00:10 reeve25