Special Tokens.

Reserved tokens like BOS, EOS, padding, and chat-role markers that structure input sequences and signal boundaries to language models.

Special tokens are reserved vocabulary elements that serve as structural markers and control signals in language model inputs, distinct from regular text tokens. These include beginning-of-sequence (BOS) and end-of-sequence (EOS) tokens that mark text boundaries, padding tokens that standardize input lengths, and role-specific markers that distinguish between user messages, assistant responses, and system instructions in conversational AI. They are essential for proper model functioning, as they provide the architectural scaffolding that allows models to understand input structure and generate appropriate responses.

Unlike content tokens that represent actual words or subwords, special tokens carry metadata about the input's organization and processing requirements. Chat models rely heavily on role markers to distinguish between different speakers in a conversation, while padding tokens ensure uniform input lengths for efficient batch processing. Some models use additional special tokens for specific functions like tool calls, code blocks, or reasoning steps. The tokenizer assigns these special tokens unique IDs that are typically reserved at the beginning or end of the vocabulary space to prevent conflicts with regular text.

Proper handling of special tokens is crucial for model performance and can significantly impact output quality when implemented incorrectly. Developers must ensure that special tokens are properly added during preprocessing and correctly interpreted during generation, as missing or malformed special tokens can lead to degraded responses or formatting issues. While most modern frameworks handle special token management automatically, understanding their role becomes important when building custom applications, fine-tuning models, or debugging unexpected behavior in AI systems.