Skip to content

fix(scan): GOAT/Crescendo generators crash on empty languages list#2602

Merged
kevinmessiaen merged 1 commit into
Giskard-AI:mainfrom
chuenchen309:fix/goat-crescendo-empty-languages-fallback
Jul 16, 2026
Merged

fix(scan): GOAT/Crescendo generators crash on empty languages list#2602
kevinmessiaen merged 1 commit into
Giskard-AI:mainfrom
chuenchen309:fix/goat-crescendo-empty-languages-fallback

Conversation

@chuenchen309

Copy link
Copy Markdown
Contributor

What

Both GOATAttackScenarioGenerator._select_objectives and CrescendoAttackScenarioGenerator._select_objectives pick a random language via languages[int(rng.integers(len(languages)))], with no guard for an empty languages list. vulnerability_scan() accepts languages: list[str] with no validation, so an empty list is easy to hit (e.g. a caller building the list programmatically), and raises ValueError: high <= 0 from numpy instead of producing scenarios.

The sibling KnowledgeBaseScenarioGenerator._sample_languages already handles this exact case correctly:

if not languages:
    return ["en"] * scenario_count

GOAT and Crescendo look like copy-pasted siblings (same objectives-dict structure, same _select_objectives body) that never received this guard.

Repro:

await GOATAttackScenarioGenerator().generate_scenario(
    ScenarioContext(description="A safety chatbot", languages=[])
)
# ValueError: high <= 0

Fix

languages = languages or ["en"] in both generators, mirroring the existing correct fallback in KnowledgeBaseScenarioGenerator.

Test plan

  • Added a regression test to both test_goat.py and test_crescendo.py asserting languages=[] falls back to "en" instead of raising.
  • Verified red/green: reverted the fix locally, confirmed both new tests fail with ValueError: high <= 0; restored the fix, confirmed all 14 tests in both files pass.
  • Ran the full giskard-scan package test suite (155 tests) — all pass.
  • make format / make lint / pre-commit (ruff, basedpyright, detect-secrets) — all clean.

AI-Generated disclosure

Found and fixed with AI-assisted code review (Claude Code), used with a human in the loop per this repo's AGENTS.md. I personally reproduced the crash, verified the fix against the sibling generator's existing correct pattern, and reviewed the diff before opening this PR.

Both GOATAttackScenarioGenerator._select_objectives and
CrescendoAttackScenarioGenerator._select_objectives pick a random
language via `languages[int(rng.integers(len(languages)))]` with no
guard for an empty `languages` list. vulnerability_scan() accepts
languages: list[str] with no validation, so an empty list raises
`ValueError: high <= 0` from numpy instead of producing scenarios.

The sibling KnowledgeBaseScenarioGenerator._sample_languages already
handles this exact case correctly: `if not languages: return ["en"] *
scenario_count`. GOAT/Crescendo look like copy-pasted siblings (same
objectives-dict structure, same _select_objectives body) that never
received this guard.

Fix: `languages = languages or ["en"]` in both generators, mirroring
the existing correct fallback.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a fallback to English (["en"]) when the languages list is empty or falsy in both the Crescendo and GOAT attack scenario generators, preventing potential crashes during scenario generation. Corresponding unit tests have been added to verify this fallback behavior. There are no review comments provided, and I have no additional feedback as the changes are clean and well-tested.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@kevinmessiaen kevinmessiaen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@kevinmessiaen
kevinmessiaen enabled auto-merge (squash) July 16, 2026 03:50
@kevinmessiaen
kevinmessiaen merged commit 9f9ed89 into Giskard-AI:main Jul 16, 2026
28 of 49 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

2 participants