fix(ai-red-teaming): collect multimodal attack results via assessment.run()#102
Merged
Merged
Conversation
….run() The generated multimodal workflow ran each attack with `await attack.run()` directly on the multimodal Study. Only `Assessment.run(study)` appends the AttackResult to `assessment.attack_results`; running the Study directly left that list empty, so `_write_local_analytics` reported "0 finished trials" even though the trials executed and traced to the platform. This produced a confusing false negative: a real SageMaker Gemma3-vision run completed successfully (trials + judge scores) yet the CLI showed 0 trials and wrote no analytics file. Changes: - Run the attack through `await assessment.run(attack)` so the result is collected into `assessment.attack_results` and uploaded (also feeds the local analytics writer). Every non-multimodal generator already does this. - Fix the per-set except handler to reference the real loop variable (`set_number`) instead of an undefined `i`, which would raise NameError inside the handler and mask the true error. - Regression tests: assert the generated script uses `assessment.run(attack)` and not `attack.run()`, and that the error handler uses `set_number`. Both fail on the pre-fix template and pass after. - Fix a stale assertion in test_per_media_prompts_list (template was refactored from `PROMPTS[i]` to `set_prompt = PROMPTS[media_idx]`). - Bump capability version 1.8.0 -> 1.9.0 (minor).
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.
Summary
The generated multimodal workflow reported
0 finished trials(and wrote no analytics) even when the attack ran successfully and traced to the platform.Root cause: the multimodal template ran each attack with
await attack.run()directly on theStudy. OnlyAssessment.run(study)appends theAttackResulttoassessment.attack_results(assessment.py). Running the Study directly left that list empty, so_write_local_analyticssaw no results → "0 finished trials". Every non-multimodal generator already usesassessment.run(...).Discovered while probing a real SageMaker Gemma3-vision endpoint: trials executed, judge scored them, yet the CLI showed 0 trials.
Changes
await attack.run()→await assessment.run(attack)in the multimodal main template (collects + uploads the result; also feeds local analytics).excepthandler to use the real loop varset_numberinstead of undefinedi(which raisedNameErrorinside the handler, masking real errors).assessment.run(attack)and notattack.run(), and that the handler usesset_number.test_per_media_prompts_listassertion (PROMPTS[i]→set_prompt = PROMPTS[media_idx]after a prior refactor).1.8.0 → 1.9.0(minor).Testing
TestGenerateMultimodalAttack: 17 passed (editable SDK 2.0.35).Note
data/mmsafety_illegal_0.pngin the workspace is a JPEG mislabeled.png; this is a data-hygiene issue, not the cause here (the workflow re-encodes media via PIL). The 0-trials symptom was purely theattack.run()bug.