Inference and generation

Stop sequence

stable definition
Machine-readable Download Markdown

Definition

A stop sequence is a configured text pattern that ends generation when the model produces it. Applications use stop sequences to delimit records, prevent the model from continuing into the next example, or hand control back to a parser or workflow.

The exact behavior is provider-specific. An API may accept several stop strings, report which one matched, and omit the matched string from returned text. Models operate on tokens, but a configured text sequence can map to one token or several. Do not assume that a human-visible character is a single-token boundary.

Operational significance

A stop sequence is a formatting and control convenience, not a semantic verifier. It fires only when the generated surface form matches. The model can express the same meaning without the exact string, produce the string inside quoted data, or stop before completing a JSON object or tool call. Parse and validate the returned artifact, and use external state to decide whether an agent's task is actually done.

Choose delimiters that are unlikely to occur in legitimate content, test tokenization and streaming behavior on the target API, and inspect the provider's stop reason. If arbitrary user or retrieved text can contain the delimiter, escaping or a schema-aware protocol is safer than raw string matching.

Distinguish it from nearby terms

  • A maximum-token limit stops generation after a quantity of generated tokens, whether or not a delimiter appears.
  • Natural completion means the model or API decided the response was finished without a custom match.
  • A semantic stopping condition asks whether the task state satisfies a goal. That decision belongs in the workflow, not in a magic text suffix.

Check your understanding

An extractor uses END as a stop sequence, and a source document legitimately contains that word. Predict the failure and name a safer boundary for the structured record.