Skip to content

Commit

Permalink
guard against Nones in message history when rewriting outputs for lea…
Browse files Browse the repository at this point in the history
…kreplay / attempt history
  • Loading branch information
leondz committed Jan 15, 2025
1 parent 0315908 commit 8b71baa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
7 changes: 4 additions & 3 deletions garak/probes/leakreplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ def _attempt_prestore_hook(self, attempt: Attempt, seq: int) -> Attempt:

def _postprocess_hook(self, attempt: Attempt) -> Attempt:
for idx, thread in enumerate(attempt.messages):
attempt.messages[idx][-1]["content"] = re.sub(
"</?name>", "", thread[-1]["content"]
)
if thread[-1]["content"] is not None:
attempt.messages[idx][-1]["content"] = re.sub(
"</?name>", "", thread[-1]["content"]
)
return attempt


Expand Down
8 changes: 8 additions & 0 deletions tests/probes/test_probes_leakreplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import garak._plugins
import garak.attempt
import garak.cli
import garak.probes.leakreplay


def test_leakreplay_hitlog():
Expand All @@ -29,3 +30,10 @@ def test_leakreplay_output_count():
p.generator = g
results = p._execute_all([a])
assert len(a.all_outputs) == generations


def test_leakreplay_handle_incomplete_attempt():
p = garak.probes.leakreplay.LiteratureCloze80()
a = garak.attempt.Attempt(prompt="IS THIS BROKEN")
a.outputs = ["", None]
p._postprocess_hook(a)

0 comments on commit 8b71baa

Please sign in to comment.