Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

BUG: get_jailbreak_templates(num_templates=0) returns every template and the Jailbreak scenario accepts num_jailbreaks below 1

Aperta
#3,417 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@ShivamSharma43 ci sta già lavorando.

Dal 22/10/2026.

  • #3418 di @ShivamSharma43 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
ai, security, testing

Direzione di ricerca

Read TextJailBreak.get_jailbreak_templates and Jailbreak.set_params_from_args, then inspect the existing validation for num_jailbreak_attempts. Add or update focused tests for invalid num_templates values and num_jailbreaks below 1; done means both APIs reject these inputs with clear ValueErrors. Pull request #3418 is already open, so check its changes and discussion before starting.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

TextJailBreak.get_jailbreak_templates(num_templates=...) only samples when num_templates is truthy (if num_templates:), and nothing checks the value:

  • num_templates=0 returns all templates (650 on main) instead of zero or an error. The docstring says None is the way to get all of them.
  • num_templates=-1 fails inside random.sample with the unrelated Sample larger than population or is negative.
  • num_templates=True returns one template, and 2.5 fails with TypeError: can't multiply sequence by non-int of type 'float'.

The Jailbreak scenario passes its num_jailbreaks run parameter through as num_jailbreaks or _DEFAULT_NUM_JAILBREAKS, and set_params_from_args checks only num_jailbreak_attempts. So num_jailbreaks=0 (for example --num-jailbreaks 0 on the CLI) silently runs the default random sample of 2 templates, and num_jailbreaks=-1 is accepted and only fails later in initialize_async with the random.sample message.

Steps/Code to Reproduce
from pyrit.datasets import TextJailBreak

print(len(TextJailBreak.get_jailbreak_templates()))
print(len(TextJailBreak.get_jailbreak_templates(num_templates=0)))
print(len(TextJailBreak.get_jailbreak_templates(num_templates=True)))
TextJailBreak.get_jailbreak_templates(num_templates=-1)
import asyncio
from unittest.mock import MagicMock

from pyrit.scenario.scenarios.airt.jailbreak import Jailbreak
from pyrit.score import TrueFalseScorer
from pyrit.setup import IN_MEMORY, initialize_pyrit_async

asyncio.run(initialize_pyrit_async(memory_db_type=IN_MEMORY))

scenario = Jailbreak(objective_scorer=MagicMock(spec=TrueFalseScorer))
scenario.set_params_from_args(args={"num_jailbreaks": 0})  # accepted; the run uses 2 random templates
scenario.set_params_from_args(args={"num_jailbreaks": -1})  # accepted; fails later in initialize_async
Expected Results

get_jailbreak_templates raises a ValueError naming num_templates for anything other than None or an integer of at least 1, and the Jailbreak scenario rejects num_jailbreaks below 1 in set_params_from_args, the same way it already rejects num_jailbreak_attempts below 1.

Actual Results
650
650
1
ValueError: Sample larger than population or is negative

Both set_params_from_args calls return without error.

Screenshots

N/A

Versions
  • OS: Windows 11
  • Python version: 3.11.9
  • PyRIT version: installed from main (4cb71734) in editable mode
Lingua principale
Python
Stelle
4.6k
Fork
962
Merge medio
2g 13h
PR unite (30g)
423

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di microsoft/PyRIT

Tutte le issue di microsoft/PyRIT

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.