Stop sequence
Definition
A string sent with a request that makes the model stop generating as soon as it produces that text.
In more detail
In Claude's Messages API you pass stop_sequences; when one matches, the response reports a stop_reason of stop_sequence and says which string fired. OpenAI's Chat Completions API takes up to four strings in stop. A prompt that asks for an answer wrapped in tags can stop at the closing tag, so nothing extra follows it.
Stop sequences were common with completion-style prompts and matter less now that chat models end their turn on their own and structured output modes exist. Pick strings that cannot appear in a valid answer, and check support per model: OpenAI's reference says o3 and o4-mini do not accept stop.
Related terms
Max tokens
A request setting that caps how many tokens a model may generate in its reply; the model can stop earlier but never goes past the cap.
Prompt template
A prompt with placeholders, such as {question} or {context}, that code fills in at run time so the instructions are reused.
Structured outputs
Constraining or validating model output so it matches a schema, usually JSON Schema, and can be parsed reliably by your code.
Token
The unit of text a model reads and writes, often a word or part of a word; in English a token averages about four characters of text.
Read more about Stop sequence
- LLM API parameters cheat sheet
Temperature, top_p, max tokens, stop, seed, logprobs, JSON output and reasoning effort, with exact names for OpenAI, Claude and Gemini, checked on the API docs.
- Prompt engineering
Writing clear, testable instructions for models and checking them on real inputs.
- Get reliable JSON from an LLM with structured outputs
Describe the output as a schema, let the provider enforce it, validate it with Pydantic AI or the AI SDK, and handle failures.
- Max tokens
A request setting that caps how many tokens a model may generate in its reply; the model can stop earlier but never goes past the cap.