fix(airt): normalize attacks arg in generate_category_attack#35
Merged
Conversation
The `attacks` parameter was iterated character-by-character when passed
as a bare string, producing cryptic "Unknown attack: 't'" errors and
making the entire category-sweep path unusable.
- Add _normalize_attack_names() to accept list, comma-separated string,
single name, or stringified-list noise; mirrors generate_attack's
attack_type.split(",") handling.
- Return a clear validation error instead of a single-character failure.
- Widen the tool annotation to list[str] | str.
- Add TestNormalizeAttackNames regression coverage.
- Document the failure signature in error-troubleshooting skill.
- Add category-tool auto-fallback guidance to the agent instructions.
attack_runner.py does not import typing as t, so the t.Any annotation tripped ruff F821 (undefined name) in CI. Use the builtin object annotation, which needs no import.
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.
Problem
generate_category_attack'sattacksparameter was iterated character-by-character when passed as a bare string, producing cryptic errors likeUnknown attack: 't'/Unknown attack: '['. This made the entire category-sweep path effectively unusable — no format (bare string, full SDK name, JSON list) worked.Root cause: the runner read
attacks_raw = params.get("attacks", [])and loopedfor a in attacks_rawdirectly, so"tap"became['t', 'a', 'p']. By contrast,generate_attackcorrectly doesattack_type.split(",").Fix
scripts/attack_runner.py: add_normalize_attack_names()accepting a list (["tap", "goat"]), comma-separated string ("tap,goat"), single name ("tap"), or stringified-list noise ("['tap']"). Return a clear validation error instead of a single-character failure.tools/attacks.py: widen theattacksannotation tolist[str] | str.tests/test_attack_runner.py: addTestNormalizeAttackNamesregression coverage (10 cases + explicit "must not split to chars" assertion).skills/error-troubleshooting/SKILL.md: document the single-character failure signature.agents/ai-red-teaming-agent.md: add category-tool auto-fallback guidance.Verification
py_compilepasses on all changed Python files.generate_category_attack(attacks=["tap"], categories=["violence"], …)— it now parses correctly, loads bundled violence goals, and runs a real 3-goal sweep to completion.