Add model-free GBNF grammar validator#22
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a new standalone Rust crate (llama-cpp-gbnf) that validates GBNF grammars by calling into llama.cpp’s native grammar parser/engine via a new llama-cpp-bindings-sys FFI wrapper, enabling grammar validation without loading a model.
Changes:
- Introduces
llama-cpp-gbnfcrate with a publicvalidate_gbnf(grammar, root)API and unit tests covering common validation outcomes. - Adds a new C/C++ FFI surface (
wrapper_gbnf.h/.cpp) to validate grammars using llama.cpp internals and exposes it viawrapper.h. - Wires the new crate into the workspace, unit test runs, and coverage gating.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| Makefile | Adds llama-cpp-gbnf to unit test execution and coverage gating. |
| Cargo.toml | Registers llama-cpp-gbnf as a workspace member and workspace dependency. |
| Cargo.lock | Locks the new crate and its dependencies. |
| llama-cpp-gbnf/Cargo.toml | Defines the new crate package metadata, dependencies, and lint configuration. |
| llama-cpp-gbnf/src/lib.rs | Establishes crate-level lint policy and exports modules. |
| llama-cpp-gbnf/src/gbnf_validation_error.rs | Adds a typed error enum for grammar validation outcomes. |
| llama-cpp-gbnf/src/validate_gbnf.rs | Implements the Rust validation API and unit tests. |
| llama-cpp-bindings-sys/wrapper.h | Includes the new GBNF wrapper header for bindgen/FFI exposure. |
| llama-cpp-bindings-sys/wrapper_gbnf.h | Declares the new validation status enum and validation function. |
| llama-cpp-bindings-sys/wrapper_gbnf.cpp | Implements model-free grammar validation against llama.cpp’s grammar parser/engine. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Validate GBNF grammars against llama.cpp's own parser without loading a model.
🤖 Generated with Claude Code