AI Glossary / Prompting and human-AI interaction / Intermediate
Stop sequence
Definition
A stop sequence is a short string of text that tells a language model to end its output the moment it would produce that string. The model stops before showing the string, so the reply is cut at a chosen point. It is a setting in the model's request, not part of the prompt wording, and some tools call it a stop token, stop string or end marker.
What it means
Language models write one small piece of text at a time and keep going until something tells them to stop. Normally that is the model's own sense that the answer is finished, or a length limit. A stop sequence adds a third option: you pick a phrase, and as soon as the model is about to write it, the output ends.
In business terms, it is a tripwire for the end of a reply. You use it when you want the output to end at a known boundary, such as the end of one answer, one list item or one field in a form. It helps keep outputs short, predictable and easy for other software to read. It does not make the model smarter or more accurate. It only controls where the text ends.
How it works
You send a request to the model with your prompt and, as a separate setting, one or more stop sequences. Many providers allow a small number of them, but limits vary. The model then generates text step by step. After each step, the system checks whether the newest text completes one of your stop sequences.
If it does, generation halts at once. In most systems the stop sequence itself is not included in the returned text, though this varies, so test it. Anything the model might have written after that point is never produced, which also means you are not billed for it.
A stop sequence is different from a length limit. A length limit cuts the text after a set amount, often in the middle of a sentence. A stop sequence cuts at a meaningful boundary you chose. Many teams use both: the stop sequence for clean endings and a length limit as a safety net. Matching is usually exact, so a stop sequence of END will not fire if the model writes End or the END, with its spacing changed.
Three practical examples
- Finance team: An analyst asks a model to draft one-line explanations for each variance in a monthly report. The prompt ends each explanation with the marker ###, and the team sets ### as the stop sequence. Each call returns exactly one explanation, which a script then places in the matching spreadsheet row.
- Retailer: A shop builds a product-description tool that fills a template with a title, a short blurb and a care note. The prompt shows the template with a final line reading ---END---. Setting ---END--- as the stop sequence stops the model from adding extra commentary after the care note.
- Support desk: A support team has the model write a suggested reply and nothing else. In the prompt, a transcript labeled Customer: and Agent: precedes the draft. The team sets Customer: as the stop sequence so the model never invents the customer's next message and keeps writing a fake conversation.
Think of it this way
A stop sequence is like a finish line painted across a running track: the runner, meaning the model, keeps going until the moment it would cross the line, and then the race is called. The analogy stops working in one place: a runner knows where the line is, but the model does not. It only learns about the stop sequence through the system, so you still need your prompt to steer it toward ending in the right place.
Worked example
A small accounting firm uses a model to write a one-sentence note for each of 40 flagged invoices. Without a stop sequence, the model often adds a second and third sentence, averaging 60 words per invoice. With the marker ### set as the stop sequence and the prompt ending each note with ###, each note averages 20 words.
The arithmetic: before, 40 invoices x 60 words = 2,400 words. After, 40 invoices x 20 words = 800 words. That is 2,400 - 800 = 1,600 fewer words, or about two thirds less text to review. If a reviewer reads 200 words a minute, review time falls from 2,400 / 200 = 12 minutes to 800 / 200 = 4 minutes. The numbers are invented, but the pattern is the point: a clean stop makes the output smaller and easier to check.
Illustrative case study
Fictional case: Harbor Lane Outfitters, a made-up online camping retailer, built a tool that wrote short answers to customer questions from its help pages. The team set the stop sequence to the word Question: so the model would stop before inventing a follow-up question. In testing it worked well.
In live use, a customer asked about a product whose name contained the text Question: Mark, a model line. The reply cut off in the middle of the product name, and the customer received a half-sentence. The team found that the stop sequence matched text inside a legitimate answer.
They fixed it in two steps. They replaced the plain word with a rare marker, ###END###, that never appears in normal text, and they updated the prompt to end every answer with it. They also added a check that flagged any reply under a minimum length for human review. Cut-off replies stopped appearing, and the team added a note to their prompt guide: choose stop sequences that cannot occur by accident.
Common misconceptions and mistakes
A stop sequence makes the model's answer more accurate. It only controls where the text ends, and accuracy still depends on the prompt, the model and the input.
A stop sequence is the same as a length limit. A length limit cuts after a set amount of text, often mid-sentence, while a stop sequence cuts at a boundary you chose.
Any common word makes a good stop sequence. A common word can appear inside a legitimate answer and cut it off early, so a rare marker is safer.
The stop sequence always shows up in the returned text. In most systems it is left out, but this varies by provider, so test your setup.
Business use
To start, pick one workflow where output is read by software or pasted into a fixed template, such as one answer per row or one reply per ticket. Add a rare marker to the prompt, set it as the stop sequence, and run a batch of real examples. Check that outputs end where you expect and that no answer is cut short. Keep the marker in a shared prompt guide so others reuse it.
Measure the share of outputs that end cleanly, the share that are cut off too early, average output length and the time people spend fixing endings. The cost is small: it is a setting, not a new tool. The risks are early cut-offs from poorly chosen markers, differences between providers in how they handle the setting, and a false sense that the output is controlled when only its ending is. Keep a length limit and a human spot check in place.
People also ask
What is the difference between a stop sequence and a max token limit?
A max token limit ends the output after a set amount of text, even mid-sentence. A stop sequence ends it when a chosen string would appear, which gives a cleaner break. Many teams use both.
Can I use more than one stop sequence?
Often yes, but the number allowed varies by provider. The model stops at whichever sequence it would reach first.
Does the stop sequence appear in the output?
In most systems it is left out of the returned text, but this varies. Test your setup before relying on it.
Check your understanding
In the worked example, how many words did the firm save across 40 invoices?
Answer: 1,600 words. Before, 40 x 60 = 2,400 words. After, 40 x 20 = 800 words. The difference is 2,400 - 800 = 1,600.
Why did Harbor Lane Outfitters get cut-off replies?
Answer: Their stop sequence, the word Question:, also appeared inside a real product name, so the model stopped in the middle of a legitimate answer.
Why is a rare marker like ###END### better than a common word?
Answer: A rare marker is unlikely to appear naturally inside an answer, so it will not cut the text off early by accident.
Does a stop sequence improve the quality of the answer?
Answer: No. It only controls where the output ends. Quality depends on the prompt, the model and the input.
Related terms
- Token
- Temperature
- Prompt
- System prompt
- Context window
- Delimiter (prompting)
- Max tokens
- Structured output
- Delimiter
Learn next
Try it on one small task: write a prompt that ends each answer with a rare marker, set that marker as the stop sequence, and run ten real examples. Then read about max tokens and structured output to see how endings and formats can be controlled together.
More in Prompting and human-AI interaction
- Soft prompt tuning - Soft prompt tuning adapts a pretrained model by learning a small set of continuous prompt vectors while keeping the base model's weights fixed.
- Source citation - Source citation is the practice of attaching a reference to a claim so a reader can find the document, page or passage it came from.
- Step-back prompting - Step-back prompting is a prompting technique in which the model is first asked to step back from a specific question and state the broader principle...
- Sycophancy - Sycophancy in an AI assistant is a tendency to agree with, flatter, or accommodate a user's stated views at the expense of an independent, evidence-based...
- Thinking budget - A thinking budget is a limit, set by the user or developer, on how much internal reasoning a language model may produce before it gives its final answer.
- Token budget - A token budget is a limit, set in advance, on how many tokens an AI model may read and write in a request, a task or a billing period.
Sources
OpenAI, Prompt engineering guide: https://platform.openai.com/docs/guides/prompt-engineering Jurafsky and Martin, Speech and Language Processing: https://web.stanford.edu/~jurafsky/slp3/ Google, Machine Learning Glossary: https://developers.google.com/machine-learning/glossary The sources were consulted for how language models generate text step by step and how prompting settings are described; the examples, analogy, worked example and case are original educational illustrations. Checked 10 Nov 2026.