1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! Grammar-constrained decoding for token-by-token generation.
//!
//! This module provides the [`TokenConstraint`] trait and concrete implementations
//! that restrict which tokens the model can emit at each decoding step:
//!
//! - [`NoConstraint`] — passthrough, all tokens allowed
//! - [`RegexConstraint`] — restricts output to strings matching a regex pattern
//! - [`JsonConstraint`] — restricts output to syntactically valid JSON
//! - [`AllowListConstraint`] — restricts output to one of a finite set of token sequences
//! - [`SequenceConstraint`] — forces output to reproduce a specific token sequence
//! - [`LengthConstraint`] — enforces hard minimum and maximum generation lengths
//!
//! The [`ConstrainedSampler`] wraps a [`crate::sampling_advanced::SamplerChain`] and
//! applies a mask to logits before sampling so that only valid continuations are drawn.
//!
//! ## Example
//! ```rust
//! use oxibonsai_runtime::constrained_decoding::{ConstrainedSamplerBuilder, TokenConstraint};
//!
//! let mut sampler = ConstrainedSamplerBuilder::new(128, 42)
//! .with_json_constraint();
//! assert!(!sampler.is_complete());
//! ```
//!
//! # Module structure
//!
//! Phase 30B split the monolithic `constrained_decoding.rs` (1966 lines) into
//! focused sub-modules; all external `crate::constrained_decoding::*` access
//! paths are preserved through the re-exports below.
//!
//! - [`error_trait`][] — [`ConstraintError`], the [`TokenConstraint`] trait,
//! and the passthrough [`NoConstraint`].
//! - [`regex`][] — NFA-based [`RegexConstraint`].
//! - [`json`][] — JSON-grammar [`JsonConstraint`] and its [`JsonParseState`].
//! - [`sampler`][] — [`ConstrainedSampler`] and [`ConstrainedSamplerBuilder`].
//! - [`allow_list`][] — [`AllowListConstraint`].
//! - [`sequence`][] — [`SequenceConstraint`].
//! - [`length`][] — [`LengthConstraint`].
pub use AllowListConstraint;
pub use ;
pub use ;
pub use LengthConstraint;
pub use RegexConstraint;
pub use ;
pub use SequenceConstraint;