Many systems that turn language into structured output, such as database queries, dialogue states, or category labels, restrict the model's output with a grammar. A grammar here is a formal set of rules listing which outputs are allowed. The restriction helps a great deal. A grammar-constrained language model reaches 100% structurally valid output, and a small model gains 30 points of accuracy on zero-shot hierarchical classification (GRAMMAR-LLM). But a grammar written or induced from yesterday's data slowly goes stale. New labels, new query shapes, and new dialogue domains appear, and the constrained system cannot emit them. It produces a valid output that is wrong, and it does so silently. Because the system can only produce what the grammar allows, its own outputs never reveal the problem. Any monitor or adaptation rule that learns from those outputs is blind to exactly the shifts that matter.
We propose to watch a different quantity: how much probability the underlying model wanted to put on outputs the grammar forbids. We call this the constraint pressure. It costs almost nothing to compute, since the model's full next-token distribution is already produced before the grammar masks it. It is a single number per input, so a fast streaming statistical test can monitor it. When its distribution shifts, the system has evidence that the world has moved past its grammar. The grammar can then be loosened or grown inside a known outer language, which keeps the structural guarantee.
Core Claim
Grammar-constrained decoders face a censoring problem that ordinary concept-drift methods do not address. Concept drift means the statistical relationship between inputs and correct outputs changes over time. Suppose a system adapts rule weights by counting which rules its own outputs use. A rule that is absent from the grammar always has a count of zero, whatever the users are doing. The same holds for any detector built on output-side statistics such as constrained entropy, parse frequencies, or slot-transition counts. All of them are computed after the constraint has already removed the evidence.
For an input $x$ decoded under grammar $G$, define the constraint pressure as
$$r(x) = \frac{1}{T}\sum_{t=1}^{T} -\log \sum_{v \in A_t(G)} p_\theta(v \mid x, y_{<t}),$$
where $p_\theta$ is the unconstrained model's next-token distribution, $y_{<t}$ is the constrained prefix generated so far, $A_t(G)$ is the set of tokens the grammar's pushdown automaton allows at step $t$, and $T$ is the output length. The value $r(x)$ is zero when the model agrees with the grammar. It grows when the model keeps reaching for forbidden continuations. Individual inputs can have high pressure simply because they are hard. We therefore do not threshold $r(x)$ per input. Instead we test whether the recent distribution of $r$ differs from a reference window.
The claim has two parts. First, a streaming test on $r$ detects the arrival of structures outside the grammar faster, and with fewer false alarms, than detectors built on constrained outputs or on model disagreement. Second, a system that answers such alarms by growing its task grammar inside a fixed outer grammar recovers task accuracy under drift while keeping 100% validity. Neither static grammars nor unconstrained decoding achieves both.
The claim has a clear boundary. The signal only exists when the base model has some latent knowledge beyond the narrow grammar. That is the common modern case: a capable language model paired with a tight task grammar. If the model itself has never seen the new structure, pressure stays low. We will measure how often this happens rather than assume it away.
Research Program
The system maintains two grammars. The outer grammar $U$ is the full formal target language, for example all well-formed SPARQL queries, every node of a label taxonomy, or all syntactically valid dialogue-state strings. It never changes, and it supplies the validity guarantee. The inner task grammar $G_t$ is a weighted subset of $U$, induced from the data seen so far. It supplies the tightness that makes constrained decoding accurate. Decoding runs under $G_t$ using the GRAMMAR-LLM machinery (GRAMMAR-LLM), which compiles an LL(prefix) grammar to LL(1) and masks illegal tokens with a deterministic pushdown automaton. We reuse that method unchanged, and its logits give us $r(x)$ for free.
Monitoring uses the Incremental Kolmogorov-Smirnov test (Fast Unsupervised Online Drift Detection Using Incremental Kolmogorov-Smirnov Test). That paper keeps a stream's cumulative distribution in a randomized search tree, giving logarithmic-time updates and constant-time test statistics. Its stated limitation is that it handles only one-dimensional streams. Constraint pressure turns a combinatorial, structured drift problem into exactly such a stream, so this limitation stops mattering. The same work motivates our label-budget design, since its detector-triggered replacement matched a fully labeled model while requesting only 42% to 47% of labels. For gradual or reverting drift we also run the sequential two-sample framework of Sequential Covariate Shift Detection Using Classifier Two-Sample Tests as a second detector.
When an alarm fires, adaptation happens in two stages. In the soften stage, the system interpolates between hard masking and a weighted penalty, so outputs in $U \setminus G_t$ become reachable at a cost. This follows the rule-set penalties of the tight-coupling recognizer (Tight coupling of speech recognition and dialog management). That system downweighted rule sets using a hand-written dialogue state machine; here the penalties are set by a statistical alarm instead. In the grow stage, the system takes the high-pressure inputs from the alarm window and samples outputs under $U$ alone. It extracts the productions of $U$ that those outputs use but $G_t$ lacks. Candidates confirmed by a small label budget are added to $G_t$ at low initial weight.
New productions are spliced in through lazy compilation (Dynamic Compilation of Weighted Context-Free Grammars). That method expands nonterminals on demand and substitutes terminals without recompiling the whole grammar. It reports compilation about 50 times faster with preoptimization and automata about 39 times smaller. It also works only for a subclass of grammars, which constrains our choice of $U$.
Two lessons from the literature shape the design. The dynamic-vocabulary dialogue system (A dynamic vocabulary spoken dialogue interface) triggered grammar updates on a single acoustic out-of-vocabulary miss. Its word error rate worsened from 12.0% to 14.3% on turns without prior context, because per-event triggers misfire. We test distributions over windows for this reason. The correction-grammar work (Correction Grammars for Error Handling in a Speech Dialog System) found that searching deeper in the recognizer's ranked candidate list injects noise. We therefore draw candidate productions from sampled outputs that are checked against $U$, not from deep ranked lists.
Baselines
The naive reference point is the static constrained decoder: GRAMMAR-LLM with $G_t$ frozen at the grammar induced from the pre-drift segment. It is the strongest non-adaptive system, and its reported 100% validity and 30-point zero-shot gain on Web of Science with LLaMA 1B come from exactly this setting (GRAMMAR-LLM). A second reference is unconstrained decoding with the same model. It sees new structures but loses the validity guarantee. It runs on the same stream, with outputs parsed against $U$ to score validity.
The strongest adaptive competitor is output-count reweighting. Rule weights in $G_t$ are updated by exponentially decayed counts of the rules the system's own outputs use, and any rule of $U$ is added once its decayed count crosses a threshold under softened decoding. This is the obvious "just learn online" answer, so it gets the same softened decoding and the same label budget as our system. Its decay rate and threshold are tuned with the same number of trials on the same held-out stream. We beat it if we recover post-drift accuracy faster, measured as the area under the prequential accuracy curve after the change point, at equal validity and equal labels.
The strongest detection competitor is the heterogeneous ensemble of Detecting Compositionally Out-of-Distribution Examples in Semantic Parsing. It pairs a Transformer with a GRU recurrent network and flags inputs where the two disagree. It reports an AUROC of 96.7 on CFQ and under 1% false positives at 90% true positive rate on SCAN's JUMP and MCD splits. That work is offline, per-example detection with unconstrained models. We feed its disagreement score into the same incremental KS monitor, so both signals face identical sequential testing. This costs it a second model, whereas pressure needs none. We win if pressure matches its detection delay at lower cost, or beats it in the constrained setting, where ensemble members decoded under $G_t$ may agree on the same wrong valid output.
Two ablations isolate the key ingredient. The first uses the entropy of the constrained distribution, computed after masking, as the monitored signal. It is identical to our system except that it discards the forbidden mass. If it performs as well, the censoring argument is wrong. The second is an oracle that is told the true change point, which bounds how much of the gap is detection and how much is adaptation. A fixed-schedule baseline, which softens and grows every $k$ inputs whether or not drift occurred, tests whether detection is needed at all.
Why not just…?
Why not just drop the grammar and decode unconstrained? An unconstrained model can follow drift naturally, but GRAMMAR-LLM reports validity falling "as low as 0%" in complex zero-shot settings, along with the loss of the 30-point accuracy gain. Our experiments report both validity and accuracy for the unconstrained baseline on every stream. If it matches our accuracy post-drift while keeping near-full validity on some stream, we will report that the grammar was unnecessary there.
Why not just reweight rules from output counts? This is the most serious threat, and it fails in a specific, testable way: counts of rules absent from $G_t$ are zero by construction under hard masking. Under softened masking the counts become nonzero, but only after the system has already paid for relaxing everywhere. The comparison with an equal tuning budget settles it. If output-count reweighting recovers as fast as we do under permanent mild softening, the pressure signal adds little, and we would say so.
Why not just use ensemble disagreement or output uncertainty? The heterogeneous ensemble is a strong offline detector, and Lukovnikov et al. also show that single-model confidence fails silently under length shift. Neither was designed for the case where the decoder is constrained. The constrained-entropy ablation and the ensemble-in-KS baseline directly test whether the forbidden mass carries information those signals lack.
Why not just recompile or relax on a fixed schedule? Scheduled relaxation needs no detector, but it pays the cost of a looser grammar during stable periods, when tightness is exactly what drives accuracy. The fixed-schedule baseline measures this cost on the stable stretches before and between drifts.
Proposed Experiments
We build streams with known change points from benchmarks in the file. In CFQ and SCAN streams, inputs come first from the training distribution and then switch to the MCD, JUMP, or LENGTH splits (Detecting Compositionally Out-of-Distribution Examples in Semantic Parsing). Each $G_t$ is induced from training outputs, and $U$ is the full output language. In the Web of Science stream, sub-labels of the 134-label taxonomy are withheld and then introduced (GRAMMAR-LLM), so $G_t$ covers only the labels seen so far. The MultiWOZ stream is domain-incremental: domains enter one at a time, and the dialogue-state grammar starts with the first domains only. A second MultiWOZ condition replays turns under the 2.1 annotation scheme and then the 2.2 scheme, which serves as a real schema drift (MultiWOZ 2.1, MultiWOZ 2.2, code at budzianowski/multiwoz). The published anchors on this data come from non-streaming, fully supervised trackers: DS-DST at 51.7% joint goal accuracy on MultiWOZ 2.2, and TRADE at 45.6% on 2.1. They calibrate the task's difficulty, but they are not streaming comparisons. We found no reported result on Lacuna for drift detection or adaptation over grammar-constrained decoding on any of these streams.
The metrics are detection delay in inputs, false alarms per thousand stable inputs, structural validity against $U$, prequential task accuracy (exact match for CFQ and SCAN, accuracy for Web of Science, joint goal accuracy for MultiWOZ), labels consumed, and added latency per input. Models are LLaMA models at 1B and 8B.
The first decisive check is the censoring test. On streams where drift adds structures outside $G_t$, the constrained-entropy ablation should show much longer detection delay than pressure. If it does not, the core claim fails. The second check is the blind-spot measurement. For each drift type, we record what fraction of post-drift inputs have pressure above the stable-window 95th percentile. This tells us where the base model's latent knowledge runs out. We expect it to be high for Web of Science label growth and lower for SCAN LENGTH, given the known bias toward short outputs. The third check concerns stable-period cost. On streams with no drift, our system should match the static decoder's accuracy, since a detector that never fires leaves the grammar untouched. The fixed-schedule baseline should lose accuracy in the same stretches.
References
- GRAMMAR-LLM: Grammar-Constrained Natural Language Generation
- Fast Unsupervised Online Drift Detection Using Incremental Kolmogorov-Smirnov Test
- Sequential Covariate Shift Detection Using Classifier Two-Sample Tests
- Tight coupling of speech recognition and dialog management - dialog-context dependent grammar weighting for speech recognition
- Dynamic Compilation of Weighted Context-Free Grammars
- A dynamic vocabulary spoken dialogue interface
- Correction Grammars for Error Handling in a Speech Dialog System
- Detecting Compositionally Out-of-Distribution Examples in Semantic Parsing
- MultiWOZ 2.1: Multi-Domain Dialogue State Corrections and State Tracking Baselines
- MultiWOZ 2.2 : A Dialogue Dataset with Additional Annotation Corrections and State Tracking Baselines