Skip to content

model-free gbnf validator#21

Merged
mcharytoniuk merged 11 commits into
mainfrom
model-free-gbnf-validator
Jul 3, 2026
Merged

model-free gbnf validator#21
mcharytoniuk merged 11 commits into
mainfrom
model-free-gbnf-validator

Conversation

@mcharytoniuk

Copy link
Copy Markdown

No description provided.

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 introduces a new, model-free GBNF grammar validation crate backed by llama.cpp’s grammar engine, and refactors the workspace to build GGML once for reuse while tightening error/status handling across several FFI boundaries. It also updates imports/tests to follow a more explicit module-path style (removing many crate-level re-exports).

Changes:

  • Add llama-cpp-gbnf + llama-cpp-gbnf-sys for parsing/validating GBNF grammars without loading a model.
  • Add llama-cpp-ggml-sys and adjust build/link plumbing to reuse a single GGML build across crates.
  • Refactor public surfaces/import paths and extend many error enums to handle unrecognized FFI status codes without panicking.

Reviewed changes

Copilot reviewed 132 out of 133 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Makefile Add clean target; expand coverage/test packages
llama-cpp-test-harness/tests/harness_self_test.rs Update imports for new module paths/macros
llama-cpp-test-harness/src/phase_state.rs Update MtmdContext import path
llama-cpp-test-harness/src/load_key.rs Update MTMD type import paths
llama-cpp-test-harness/src/llama_tests_main_macro.rs Adjust macro call path for run
llama-cpp-test-harness/src/llama_fixture.rs Update MtmdContext import path
llama-cpp-test-harness/src/lib.rs Tighten clippy denies; remove re-exports
llama-cpp-test-harness/src/harness_run_error.rs Update LlamaCppError import path
llama-cpp-test-harness/src/execution_phase.rs Update ModelSource import path
llama-cpp-test-harness-macros/src/lib.rs Tighten clippy denies
llama-cpp-test-harness-macros/src/expand.rs Update generated paths; inventory submit path
llama-cpp-log-decoder/src/lib.rs Tighten clippy denies
llama-cpp-ggml-sys/src/lib.rs New crate root (currently empty)
llama-cpp-ggml-sys/CMakeLists.txt CMake entry for building vendored ggml
llama-cpp-ggml-sys/Cargo.toml New sys crate metadata/features
llama-cpp-ggml-sys/build.rs Build-script entrypoint to build GGML
llama-cpp-gbnf/src/validation.rs New Accepted/Rejected result enum
llama-cpp-gbnf/src/lib.rs New public modules for validator crate
llama-cpp-gbnf/src/gbnf_parse_error.rs New parse error enum
llama-cpp-gbnf/src/gbnf_matcher.rs Incremental matcher over grammar state
llama-cpp-gbnf/src/gbnf_grammar.rs Safe-ish wrapper around grammar handle
llama-cpp-gbnf/Cargo.toml New validator crate manifest
llama-cpp-gbnf-sys/wrapper_gbnf.h New C ABI for grammar engine wrapper
llama-cpp-gbnf-sys/wrapper_gbnf.cpp C++ wrapper implementation (parser/matcher)
llama-cpp-gbnf-sys/src/lib.rs Raw Rust FFI declarations for wrapper
llama-cpp-gbnf-sys/Cargo.toml New sys crate manifest; ggml dependency
llama-cpp-gbnf-sys/build.rs Build-script entrypoint to build wrapper
llama-cpp-error-recorder/src/lib.rs Tighten clippy denies; remove re-exports
llama-cpp-bindings/src/tool_call_template_overrides/qwen3_json_inside_tool_call.rs Update types imports to module paths
llama-cpp-bindings/src/tool_call_template_overrides/qwen_xml_tags.rs Update types imports to module paths
llama-cpp-bindings/src/tool_call_template_overrides/mod.rs Remove re-exports from module
llama-cpp-bindings/src/tool_call_template_overrides/mistral3_arrow_args.rs Update types imports to module paths
llama-cpp-bindings/src/tool_call_template_overrides/known_marker_candidates.rs Update ToolCallMarkers/ArgsShape imports
llama-cpp-bindings/src/tool_call_template_overrides/glm47_key_value_tags.rs Update types imports to module paths
llama-cpp-bindings/src/tool_call_template_overrides/gemma4_call_block.rs Update types imports to module paths
llama-cpp-bindings/src/tool_call_template_overrides/detect.rs Update ToolCallMarkers import path
llama-cpp-bindings/src/tool_call_format/xml_function_tags.rs Update types + error import paths
llama-cpp-bindings/src/tool_call_format/tool_call_format_outcome.rs Update ParsedToolCall + error import paths
llama-cpp-bindings/src/tool_call_format/paired_quote_args.rs Update types + error import paths
llama-cpp-bindings/src/tool_call_format/mod.rs Update imports; adjust test module paths
llama-cpp-bindings/src/tool_call_format/key_value_xml_tags.rs Update types + error import paths
llama-cpp-bindings/src/tool_call_format/json_object.rs Update types + error import paths
llama-cpp-bindings/src/tool_call_format/bracketed_args.rs Update types + error import paths
llama-cpp-bindings/src/token/data_array.rs Map unknown sampler status to typed error
llama-cpp-bindings/src/sampling.rs Add gbnf root validation; typed status errors
llama-cpp-bindings/src/sampled_token_classifier.rs Update MTMD/types imports; remove re-exports
llama-cpp-bindings/src/mtmd/mtmd_tokenize_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/mtmd/mtmd_input_chunk.rs Map unknown status to typed error; rename vars
llama-cpp-bindings/src/mtmd/mtmd_init_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/mtmd/mtmd_eval_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/mtmd/mtmd_encode_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/mtmd/mtmd_default_marker.rs Update wording in docs/tests
llama-cpp-bindings/src/mtmd/mtmd_context.rs Map unknown statuses to typed errors; rename vars
llama-cpp-bindings/src/mtmd/mtmd_bitmap.rs Map unknown status to typed error; rename constants
llama-cpp-bindings/src/mtmd/mtmd_bitmap_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/mtmd.rs Remove MTMD module re-exports
llama-cpp-bindings/src/model/params.rs Update error imports; map unknown fit status
llama-cpp-bindings/src/model/llama_chat_message.rs Update error import path
llama-cpp-bindings/src/llguidance_sampler.rs Update error-recorder + GrammarError imports
llama-cpp-bindings/src/llama_backend.rs Update Result/LlamaCppError import paths
llama-cpp-bindings/src/llama_backend_device.rs Remove pub re-export; use direct import
llama-cpp-bindings/src/lib.rs Tighten clippy denies; remove crate re-exports
llama-cpp-bindings/src/json_schema_to_grammar.rs Map unknown status to typed error
llama-cpp-bindings/src/ingest_prompt_chunk.rs Update MTMD import paths
llama-cpp-bindings/src/extract_reasoning_markers_from_probe_renders.rs Use types crate ReasoningMarkers
llama-cpp-bindings/src/error/string_to_token_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/error/sampler_apply_error.rs Add UnrecognizedStatusCode; update message
llama-cpp-bindings/src/error/sampler_accept_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/error/sample_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/error/parse_chat_message_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/error/marker_detection_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/error/llama_model_load_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/error/llama_context_load_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/error/kv_cache_seq_div_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/error/kv_cache_seq_add_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/error/json_schema_to_grammar_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/error/grammar_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/error/fit_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/error/eval_multimodal_chunks_error.rs Update MTMD import path
llama-cpp-bindings/src/error/encode_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/error/decode_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/error/apply_chat_template_error.rs Add UnrecognizedStatusCode variant
llama-cpp-bindings/src/error.rs Stop re-exporting errors; define Result alias
llama-cpp-bindings/src/context/params.rs Replace re-exports with internal use
llama-cpp-bindings/src/context/kv_cache.rs Typed mapping for unknown status codes
llama-cpp-bindings/src/context.rs Typed mapping for unknown status codes; import cleanup
llama-cpp-bindings/src/chat_message_parse_outcome.rs Update ParsedChatMessage import path
llama-cpp-bindings/Cargo.toml Add gbnf dependency; remove system-ggml features
llama-cpp-bindings-types/src/lib.rs Tighten clippy denies; remove re-exports
llama-cpp-bindings-tests/tests/vocabulary_and_metadata.rs Update imports for new module paths/macros
llama-cpp-bindings-tests/tests/sampling_and_constrained_decoding.rs Update imports for new module paths
llama-cpp-bindings-tests/tests/reasoning_markers_and_tool_calls.rs Move types to bindings-types crate
llama-cpp-bindings-tests/tests/multimodal_vision.rs Update imports; adjust SampledTokenSection path
llama-cpp-bindings-tests/tests/multimodal_image_and_audio.rs Update imports for new module paths
llama-cpp-bindings-tests/tests/multimodal_audio.rs Update prompts; update imports/macros
llama-cpp-bindings-tests/tests/model_loading_errors.rs Update error imports; update harness macro
llama-cpp-bindings-tests/tests/kv_cache_and_session.rs Update error imports; update harness macro
llama-cpp-bindings-tests/tests/embedding_and_encoder.rs Update ggml_time_us/AddBos imports
llama-cpp-bindings-tests/tests/chat_template_and_message_parsing.rs Update error/message imports; update harness macro
llama-cpp-bindings-tests/tests/backend_initialization.rs Update harness macro import path
llama-cpp-bindings-tests/src/prime_kv_cache.rs Update harness fixture import path
llama-cpp-bindings-tests/src/prime_kv_cache_with.rs Update AddBos + fixture import paths
llama-cpp-bindings-tests/src/chunk_token_breakdown.rs Update MTMD import paths
llama-cpp-bindings-tests/src/build_user_prompt_with_media_marker.rs Update chat message/marker imports
llama-cpp-bindings-tests/Cargo.toml Add deps for macros/types/inventory
llama-cpp-bindings-sys/wrapper_utils.h Add noexcept macro + shared exception capture helpers
llama-cpp-bindings-sys/wrapper_tool_calls.h Rename exception status constants
llama-cpp-bindings-sys/wrapper_tool_calls.cpp Use shared exception capture helper
llama-cpp-bindings-sys/wrapper_reasoning.h Rename exception status constants
llama-cpp-bindings-sys/wrapper_reasoning.cpp Use shared exception capture helper
llama-cpp-bindings-sys/wrapper_mtmd.h Rename status constants; rename out_return_code
llama-cpp-bindings-sys/wrapper_mtmd.cpp Use shared exception capture helper; rename vars
llama-cpp-bindings-sys/wrapper_fit.h Rename fit status constants
llama-cpp-bindings-sys/wrapper_fit.cpp Use shared exception capture helper; rename status
llama-cpp-bindings-sys/wrapper_common.h Rename status constants; add noexcept on helper
llama-cpp-bindings-sys/wrapper_chat_parse.h Rename exception status constants
llama-cpp-bindings-sys/wrapper_chat_parse.cpp Use shared exception capture helper
llama-cpp-bindings-sys/wrapper_chat_apply.h Rename exception status constants
llama-cpp-bindings-sys/wrapper_chat_apply.cpp Use shared exception capture helper
llama-cpp-bindings-sys/Cargo.toml Depend on ggml-sys; adjust build-dep features
llama-cpp-bindings-build/src/library_linking.rs Add ggml system paths; link extra ggml backends
llama-cpp-bindings-build/src/lib.rs Thread ggml system paths through build context
llama-cpp-bindings-build/src/ggml_system_paths.rs New helper to read ggml DEP_* metadata
llama-cpp-bindings-build/src/ggml_cmake_options.rs Split ggml-specific cmake configuration helpers
llama-cpp-bindings-build/src/cmake_config.rs Refactor cmake configuration into shared modules
llama-cpp-bindings-build/src/cmake_common.rs New shared cmake helpers (ccache/env/shared libs)
llama-cpp-bindings-build/src/build_ggml.rs New build routine for ggml-sys
llama-cpp-bindings-build/src/build_gbnf.rs New build routine for gbnf wrapper
Cargo.toml Add new workspace members/deps
Cargo.lock Add new crate entries/dependencies
.claude/rules/rust.md Update Rust guideline bullets/order
Comments suppressed due to low confidence (1)

llama-cpp-bindings/src/lib.rs:16

  • This crate no longer re-exports its previously public API surface (the large pub use block was removed). That is a breaking change for downstream crates (e.g., imports like llama_cpp_bindings::DecodeError or ::max_devices will fail). If this is intended, it likely needs a coordinated major/minor version bump and migration guidance; otherwise consider restoring the re-exports (or providing a prelude module) to preserve compatibility.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .claude/rules/rust.md
Comment thread llama-cpp-bindings-build/src/build_ggml.rs
Comment thread llama-cpp-gbnf-sys/wrapper_gbnf.cpp Outdated

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

Copilot reviewed 134 out of 135 changed files in this pull request and generated 4 comments.

Comments suppressed due to low confidence (2)

llama-cpp-bindings/src/lib.rs:20

  • This file removed all pub use ... re-exports from the crate root. That is a breaking API change for downstream users importing items like llama_cpp_bindings::LlamaContext / llama_cpp_bindings::GrammarError, etc. If this crate is published/consumed externally, consider either restoring the re-exports (possibly deprecated) or bumping the major version and documenting the migration path.
    llama-cpp-bindings-types/src/lib.rs:27
  • This file also removed all crate-root re-exports (e.g. llama_cpp_bindings_types::ParsedToolCall). That is a breaking API change for downstream crates. Consider restoring re-exports (possibly behind a compatibility feature) or bumping the major version and providing a migration guide.

Comment thread .claude/rules/rust.md Outdated
Comment thread llama-cpp-bindings/src/context.rs
Comment thread llama-cpp-bindings/src/context.rs
Comment thread llama-cpp-bindings-build/src/library_linking.rs

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

Copilot reviewed 134 out of 135 changed files in this pull request and generated 3 comments.

Comments suppressed due to low confidence (1)

llama-cpp-bindings/src/lib.rs:16

  • Removing the large set of pub use ... re-exports from the crate root is a breaking public API change: downstream users importing items like llama_cpp_bindings::DecodeError, llama_cpp_bindings::LlamaBackendDevice, or llama_cpp_bindings::ToolCallMarkers will no longer compile. If this is intentional, it should be accompanied by an explicit semver bump and/or a compatibility layer (e.g., keep the re-exports with #[deprecated] to provide a transition period).

Comment thread llama-cpp-bindings/src/context.rs Outdated
Comment thread llama-cpp-bindings/src/context.rs
Comment thread llama-cpp-test-harness-macros/src/expand.rs

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

Copilot reviewed 134 out of 135 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (3)

llama-cpp-bindings/src/lib.rs:70

  • Removing the crate-root pub use re-exports is a breaking public API change for llama-cpp-bindings (e.g., llama_cpp_bindings::SampledToken, llama_cpp_bindings::LlamaCppError, llama_cpp_bindings::Result, etc.). If this crate is consumed outside the workspace, consider keeping the old re-exports as #[deprecated] (or introducing a prelude module) and/or bumping the crate version according to your semver policy so downstream users don’t get an unexpected compile break.
    llama-cpp-bindings-types/src/lib.rs:17
  • llama-cpp-bindings-types no longer re-exports its common types at the crate root (e.g. llama_cpp_bindings_types::ToolCallMarkers), which is a breaking change for any downstream crates using the previous public API. Consider restoring the root re-exports as #[deprecated] (or providing an explicit prelude) and/or bumping the version to match the intended compatibility guarantees.
    llama-cpp-error-recorder/src/lib.rs:18
  • llama-cpp-error-recorder no longer re-exports its primary public types (ErrorScope, record, RecordedError) at the crate root, which is a breaking API change for downstream users. If this crate is published/consumed externally, consider keeping the old root re-exports as #[deprecated] (or adding a prelude) and/or bumping the version appropriately.

@mcharytoniuk mcharytoniuk merged commit 6f5e24b into main Jul 3, 2026
6 checks passed
@mcharytoniuk mcharytoniuk deleted the model-free-gbnf-validator branch July 3, 2026 03:16
mcharytoniuk added a commit that referenced this pull request Jul 3, 2026
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