Stop Sequence.
A predefined string that signals an LLM to halt text generation when encountered, used to control output boundaries and structure responses.
A stop sequence is a specific string or token that instructs a language model to immediately cease generating text when it encounters or produces that sequence. This mechanism serves as a crucial control tool for developers and applications, allowing them to define clear boundaries for model outputs and prevent runaway generation. Stop sequences are essential for creating predictable, structured interactions with LLMs, particularly in applications requiring specific formatting or length constraints.
Stop sequences work by being monitored during the token-by-token generation process, where the model checks each newly generated token against a list of predefined stop conditions. Common stop sequences include newline characters, specific punctuation marks, custom delimiters like "###" or "END", or even complete phrases. Multiple stop sequences can be active simultaneously, and the model will halt upon encountering any of them. The flexibility of this system allows developers to create complex structured outputs, such as JSON responses, code blocks, or conversational turns that end at natural breakpoints.
In practice, stop sequences are fundamental to prompt engineering and application development, enabling everything from chatbot turn-taking to structured data extraction. However, choosing appropriate stop sequences requires careful consideration of the expected output format and potential edge cases where the sequence might appear naturally in valid responses. A poorly chosen stop sequence might truncate legitimate content, while an overly specific one might fail to prevent unwanted continuation. Understanding stop sequences is essential for anyone working with LLM APIs or building applications that require controlled text generation.
Related terms.
- Prompt EngineeringThe practice of crafting inputs, instructions, examples, and formatting to guide language models toward producing better, more accurate outputs.
- SamplingThe method used to select each next token from a probability distribution during text generation, controlling the randomness and creativity of model outputs.
- System PromptA special instruction given to a language model before the user conversation begins, establishing the model's persona, capabilities, constraints, and context.
- InferenceThe process of running a trained AI model to generate outputs — what happens when you send a prompt and receive a response.