Skip to content

Add model-free GBNF grammar validator#22

Merged
mcharytoniuk merged 1 commit into
mainfrom
gbnf-validator
Jul 3, 2026
Merged

Add model-free GBNF grammar validator#22
mcharytoniuk merged 1 commit into
mainfrom
gbnf-validator

Conversation

@mcharytoniuk

Copy link
Copy Markdown

Validate GBNF grammars against llama.cpp's own parser without loading a model.

🤖 Generated with Claude Code

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-gbnf crate with a public validate_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 via wrapper.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.

@mcharytoniuk mcharytoniuk merged commit dec2842 into main Jul 3, 2026
7 checks passed
@mcharytoniuk mcharytoniuk deleted the gbnf-validator branch July 3, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants