arXiv:2610.28922cs.IROct 2026

Manuscript Offprint

arXiv:2610.28922

Constrained Tagging for Span Labeling

Radek Štulc, Jan Drchal

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Generative LLMs can label spans without task-specific training, but their output is not tied to positions in the input: a returned span may be absent from the input or occur several times. We present constrained tagging, a training-free method in which the model reproduces the input and wraps each span in labeled inline markup. A logits processor using a byte-level token trie and a finite-state machine admits only tokens that continue the input verbatim or form a valid tag, so the output reproduces the input exactly with labels from the given set, and spans may begin or end at any character boundary, even inside a token. Two-phase decoding lets reasoning models reason before the constraint engages. On six datasets and six open-weight models, the guarantee holds in all but 0.022% of 255,312 constrained generations, each failure a reasoning model exhausting its token budget or never closing its reasoning, and the constraint adds no measurable cost. Unlike context-based prompting, which loses 8.5% of its spans, constrained tagging locates every span it proposes on every dataset; it is as accurate on two datasets, and on the other four its errors lie in which spans the model chooses, not where they are.

1 Introduction

Classifying text spans is a fundamental problem in NLP, with applications ranging from named entity recognition and extractive question answering to grammatical error correction, toxic language detection, and other information extraction tasks. Traditionally, this problem has been addressed with encoder-only models such as BERT (Devlin et al., 2019), which directly produce token-level predictions. These models need a large annotated dataset for every task, and they must be retrained whenever the label set changes. Generative large language models (LLMs), which have grown far larger and more capable and can now reason before they answer, offer a different paradigm: they can perform

Figure

Figure 1: Constrained tagging. At every step, the processor admits only tokens that continue the input verbatim or belong to the tag markup (green) and masks all others (red), so the output reproduces x exactly, and the offsets of each span follow from where its tag was generated.

span labeling in a zero-shot setting through prompting alone, which makes them attractive when labeled data are scarce or the label set changes.

Applying generative LLMs to span labeling, however, introduces a challenge encoders do not face: once the model identifies a span of interest, how do we locate it precisely within the original input text? Generative LLMs operate autoregressively, producing output tokens without any inherent correspondence to positions in the source text. This creates a fundamental localization problem, which is particularly acute when the same surface form appears several times: simply extracting “Charles” from the model output provides no information about which occurrence was identified or where in the text it is located (Fig. 1). Generative models may also fail to copy text faithfully, producing spans that cannot be aligned to the source at all.

In this paper, we use a constrained decoding approach to span labeling. We classify spans with a tagging mechanism: the model reproduces the input text and tags each span inline, wrapping it in markup that assigns it a label (Fig. 1). A logits processor, guided by a byte-level token trie (Fredkin, 1960) and a finite-state machine, restricts the generation at every step to tokens that either continue the input verbatim or form a valid tag with a label from the given label set. Localization is therefore enforced during generation rather than recovered afterwards: the position of every span is determined by construction at the moment it is generated, the output reproduces the input exactly, and a hallucinated span or an invalid label cannot be produced. Nothing is trained: adapting the method to a new task requires only a system prompt and a set of labels (§4).

Our contributions are: (1) a training-free constrained decoding method for span labeling by tagging, which guarantees that the output reproduces the input verbatim with labels only from the given set, and places span boundaries at any character boundary, including inside a token (§4); (2) two-phase decoding, which leaves the reasoning trace of a reasoning model unconstrained and constrains only its answer, so that reasoning models, including those that may skip their reasoning, keep the guarantee (§4.4); and (3) an evaluation on six datasets covering five span-labeling tasks, with six open-weight models from three families, against unconstrained tagging and context-based prompting, showing that the guarantee holds in all but 0.022% of 255,312 constrained generations with no measurable overhead from the constraint, and that the remaining errors lie in which spans the model chooses rather than where they are (§5). 1^{1}

References (29)