pub enum GrammarError {
Show 13 variants
Syntax {
expected: String,
offset: usize,
rest: String,
},
UndefinedRule {
name: String,
rule_id: u32,
},
MissingRoot {
name: String,
},
LeftRecursion {
rule_id: u32,
name: Option<String>,
},
RepetitionTooLarge {
requested: u64,
limit: u64,
offset: usize,
},
TokenNeedsVocabulary {
token: String,
offset: usize,
},
TokenNotSingle {
token: String,
n_tokens: usize,
},
NoViableStack {
piece: String,
},
TriggerPatternInvalid {
pattern: String,
reason: String,
},
TriggerPatternFailed {
pattern: String,
reason: String,
},
LazyWithoutTriggers,
AwaitingTrigger,
Internal(&'static str),
}Expand description
What the grammar engine refused, and why.
Variants§
Syntax
A syntax error in the GBNF source. offset is the byte offset into
the grammar text where llama.cpp’s parser would have thrown, and
rest is the (truncated) input from there on, matching the
"expecting X at " + src shape of the upstream messages.
UndefinedRule
A rule was referenced but never given a ::= definition.
MissingRoot
The grammar parsed but has no rule with the requested root name.
LeftRecursion
A rule can reach itself without consuming input. llama.cpp logs “unsupported grammar, left recursion detected” and returns null.
RepetitionTooLarge
A repetition operator would expand to more rules than the engine
is willing to build. llama.cpp’s MAX_REPETITION_THRESHOLD.
TokenNeedsVocabulary
<name> token syntax was used but no vocabulary was supplied to
resolve it. <[42]> needs no vocabulary and always works.
TokenNotSingle
A <name> token did not tokenize to exactly one token.
NoViableStack
The generated text left no viable parse: every stack died. Carries the piece that killed it, as llama.cpp’s thrown message does.
TriggerPatternInvalid
A lazy grammar’s trigger pattern does not compile. llama.cpp builds
a std::regex in the constructor, which throws.
TriggerPatternFailed
A trigger pattern compiled but failed while matching – the
backtracking limit, in practice. Upstream’s std::regex has the
same failure mode and does not report it.
LazyWithoutTriggers
A grammar was made lazy with nothing that could ever switch it on, which is an unconstrained generation wearing a grammar. llama.cpp permits it; this engine will not pretend to constrain.
AwaitingTrigger
A not-yet-triggered lazy grammar was asked which tokens it forbids.
It forbids nothing, and answering “nothing” would be
indistinguishable from a grammar that allows everything – so the
question is refused. Callers test
Grammar::is_awaiting_trigger
first, as llama_grammar_apply_impl does.
Internal(&'static str)
An invariant llama.cpp asserts with GGML_ABORT. Reaching one is a
bug in this engine, not in the caller’s grammar.
Trait Implementations§
Source§impl Clone for GrammarError
impl Clone for GrammarError
Source§fn clone(&self) -> GrammarError
fn clone(&self) -> GrammarError
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for GrammarError
impl Debug for GrammarError
Source§impl Display for GrammarError
impl Display for GrammarError
impl Eq for GrammarError
Source§impl Error for GrammarError
impl Error for GrammarError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()
Source§impl From<GrammarError> for SchemaError
impl From<GrammarError> for SchemaError
Source§fn from(e: GrammarError) -> Self
fn from(e: GrammarError) -> Self
Source§impl From<GrammarError> for ConstraintError
impl From<GrammarError> for ConstraintError
Source§fn from(source: GrammarError) -> Self
fn from(source: GrammarError) -> Self
Source§impl PartialEq for GrammarError
impl PartialEq for GrammarError
impl StructuralPartialEq for GrammarError
Auto Trait Implementations§
impl Freeze for GrammarError
impl RefUnwindSafe for GrammarError
impl Send for GrammarError
impl Sync for GrammarError
impl Unpin for GrammarError
impl UnsafeUnpin for GrammarError
impl UnwindSafe for GrammarError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more