Stop sequence

Also called stop token, stop words, stop

A piece of text that tells the AI to stop writing as soon as it produces it.

A stop sequence is a string you give to a model API that ends generation when the model outputs it. If the stop sequence is "</answer>", the model stops the moment it writes those characters, and the API returns everything before them. You can usually set several stop sequences at once.

Stop sequences are a precise way to control where output ends. They are useful when you want exactly one item from a pattern that could repeat, such as one answer in a Q&A format, or when you ask for output inside tags and want nothing after the closing tag. Combined with prefilling, they let you frame a response tightly: you write the opening, the model fills the middle, the stop sequence ends it.

They are less necessary than they once were. Modern instruction-tuned models usually stop on their own when the task is done, and structured output features handle many formatting needs. Stop sequences remain handy for templates, extraction and older completion-style APIs.

Example

A prompt lists questions as "Q:" and answers as "A:". To get only one answer, the developer sets "\nQ:" as a stop sequence. The model writes its answer and stops before inventing a follow-up question.

Common mistake

Choosing a stop sequence that can appear naturally inside the answer. Stopping on "." cuts the reply after the first sentence; stopping on "Note" ends any answer that uses that word. Pick sequences that only appear at the boundary, such as a closing tag.

Find a prompt for the task in front of you.

96 prompts in 8 categories. Copy one, fill in the blanks, paste it into any model.

Browse prompts

Promptlexity is a free library of 96 AI prompts and 8 downloadable AI skills across 8 categories, plus a glossary of 64 AI and prompting terms. Each prompt shows the exact text to paste, the variables to fill in, an example of what comes back, and why it works. Each glossary term has a plain-English definition, an example and a common mistake. 6 step-by-step guides cover the basics. No signup, works with ChatGPT, Claude, Gemini and other models.

Press Esc to close