{"record":{"id":"dc7f90bedf8c0e91","repo":"oobabooga/textgen","slug":"at-least-one-of-the-stack-should-be-empty-when-eos","errorCode":null,"errorMessage":"At least one of the stack should be empty when EOS is reached. However, the stacks are {stacks}","messagePattern":"At least one of the stack should be empty when EOS is reached\\. However, the stacks are (.+?)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"modules/grammar/grammar_utils.py","lineNumber":505,"sourceCode":"                continue\n\n            pos += num_chars\n            new_stack = stack[:-1]\n            if self.grammar_encoding[pos]:\n                new_stack.append(pos)\n            new_stacks.extend(self.advance_stack(tuple(new_stack)))\n\n        return new_stacks\n\n    def accept_string(self, string: str, stacks: List[List[int]]):\n        for char in string:\n            stacks = self.accept_char(char, stacks)\n        return stacks\n\n    def accept_token_id(self, token_id: int, stacks: List[List[int]]):\n        if token_id == self.eos_token_id:\n            if stacks and all(len(stack) != 0 for stack in stacks):\n                raise Exception(\n                    f\"At least one of the stack should be empty when EOS is reached. However, \"\n                    f\"the stacks are {stacks}\"\n                )\n            return []\n\n        for byte in self.token_trie.id2str(token_id):\n            stacks = self.accept_char(byte, stacks)\n            # check updated stacks\n            # TODO, I commented this out because it will fail when the stack is empty\n            # empty stack means the end of the grammar\n            # assert stacks != []\n\n        return stacks\n\n    def accept_token_ids(self, token_ids: List[int], stacks: List[List[int]], as_string=True):\n        if as_string:\n            string = self.tokenizer.decode(token_ids)\n            stacks = self.accept_string(string, stacks)","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/oobabooga/textgen/blob/ed888c71f221df552750e1834b3654abab8ae345/modules/grammar/grammar_utils.py#L487-L523","documentation":"Error \"At least one of the stack should be empty when EOS is reached. However, the stacks are {stacks}\" thrown in oobabooga/textgen.","triggerScenarios":"Raised by the grammar FSM when end-of-sequence is reached but at least one grammar stack is non-empty. Triggers when generation stops (EOS) while the GBNF grammar still expects more symbols, typically because the model emitted EOS before completing a grammar-required structure, or because the grammar itself cannot terminate for the produced input.","commonSituations":"See trigger scenarios.","solutions":["Ensure the grammar accepts the full input so all parse stacks are empty at EOS.","Simplify or correct the grammar rules so parsing terminates cleanly before the end-of-stream token."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"ed888c71f221df552750e1834b3654abab8ae345","analyzedAt":"2026-08-15T05:24:21.000Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}