{"record":{"id":"8436f75f85a5bfe2","repo":"huggingface/transformers","slug":"each-list-in-bad-words-ids-has-to-be-a-list-of-p","errorCode":null,"errorMessage":"Each list in `bad_words_ids` has to be a list of positive integers, but is {bad_words_ids}.","messagePattern":"Each list in `bad_words_ids` has to be a list of positive integers, but is (.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/generation/logits_process.py","lineNumber":1479,"sourceCode":"            eos_token_id_list = eos_token_id.tolist()  # convert to python list before\n            bad_words_ids = list(\n                filter(lambda bad_token_seq: all(bad_token_seq != [i] for i in eos_token_id_list), bad_words_ids)\n            )\n        # Forbidding a sequence is equivalent to setting its bias to -inf\n        sequence_bias = {tuple(sequence): float(\"-inf\") for sequence in bad_words_ids}\n        super().__init__(sequence_bias=sequence_bias)\n\n    def _validate_arguments(self):\n        bad_words_ids = self.bad_word_ids\n        if not isinstance(bad_words_ids, list) or len(bad_words_ids) == 0:\n            raise ValueError(f\"`bad_words_ids` has to be a non-empty list, but is {bad_words_ids}.\")\n        if any(not isinstance(bad_word_ids, list) for bad_word_ids in bad_words_ids):\n            raise ValueError(f\"`bad_words_ids` has to be a list of lists, but is {bad_words_ids}.\")\n        if any(\n            any((not isinstance(token_id, (int, np.integer)) or token_id < 0) for token_id in bad_word_ids)\n            for bad_word_ids in bad_words_ids\n        ):\n            raise ValueError(\n                f\"Each list in `bad_words_ids` has to be a list of positive integers, but is {bad_words_ids}.\"\n            )\n\n\nclass PrefixConstrainedLogitsProcessor(LogitsProcessor):\n    r\"\"\"\n    [`LogitsProcessor`] that enforces constrained generation and is useful for prefix-conditioned constrained\n    generation. See [Autoregressive Entity Retrieval](https://huggingface.co/papers/2010.00904) for more information.\n\n    Args:\n        prefix_allowed_tokens_fn (`Callable[[int, torch.Tensor], list[int]]`):\n            This function constraints the beam search to allowed tokens only at each step. This function takes 2\n            arguments `inputs_ids` and the batch ID `batch_id`. It has to return a list with the allowed tokens for the\n            next generation step conditioned on the previously generated tokens `inputs_ids` and the batch ID\n            `batch_id`.\n\n    Examples:\n","sourceCodeStart":1461,"sourceCodeEnd":1497,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/logits_process.py#L1461-L1497","documentation":"Error \"Each list in `bad_words_ids` has to be a list of positive integers, but is {bad_words_ids}.\" thrown in huggingface/transformers.","triggerScenarios":"Raised in NoBadWordsLogitsProcessor.__init__ when an inner bad_words_ids list is empty or contains non-positive-integer token ids.","commonSituations":"Banned phrase lists containing negative ids, floats, or empty entries after tokenization of bad words.","solutions":["Ensure every entry in `bad_words_ids` contains only positive integer token ids.","Filter out negative or non-integer values before passing the list."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}