Table of Contents

Enum TextGenerationResult.StopReason

Namespace
LMKit.TextGeneration
Assembly
LM-Kit.NET.dll

Enumerates the various reasons that can lead to the termination of a text completion task.

public enum TextGenerationResult.StopReason

Fields

Unknown = 0

The reason for termination is unknown.

EndOfGeneration = 1

Indicates that the end of the sequence has been reached.

MaxTokenLimitReached = 2

Indicates that the maximum allowed number of tokens in the response has been reached.

StopSequenceDetected = 3

Indicates stopping due to detection of content that should not be prompted for further processing.

ContextSizeLimitExceeded = 4

Indicates that the context size limit has been reached, preventing further input processing.

CancellationRequested = 5

Indicates that a cancellation has been requested.

NoLogits = 6

Indicates that the model is unsuitable for tasks requiring logits, such as text completion.

ToolInvocationRequested = 7

Indicates generation halted because the model emitted a tool call request. No further tokens should be produced until the tool is executed and its result is injected.

Examples

Example: Handle different stop reasons after generation

using LMKit.Model;
using LMKit.TextGeneration;

LM model = LM.LoadFromModelID("gemma3:4b"); var conversation = new SingleTurnConversation(model); conversation.MaximumCompletionTokens = 100;

var result = conversation.Submit("Write a short essay on climate change.");

switch (result.TerminationReason) { case TextGenerationResult.StopReason.EndOfGeneration: Console.WriteLine("Model finished naturally."); break; case TextGenerationResult.StopReason.MaxTokenLimitReached: Console.WriteLine("Output was truncated at the token limit."); break; case TextGenerationResult.StopReason.StopSequenceDetected: Console.WriteLine("A stop sequence was encountered."); break; default: Console.WriteLine($"Stopped: {result.TerminationReason}"); break; }

Share