promptinject: capped probes apply settings from the wrong prompt
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_pandmax_tokensmeant 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
- Windows 11
- Python 3.12
- Direct repository checkout with git