feat: add llguidance grammar support to MaskedTag and update related functionality#119
Open
feat: add llguidance grammar support to MaskedTag and update related functionality#119
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for custom CFG (Context-Free Grammar) definitions to MaskedTag, allowing users to specify structured generation constraints beyond regex patterns. The implementation ensures that only one constraint type (regex or grammar) can be used per tag and validates grammar syntax against LLGuidance specifications.
Key changes:
- Added
grammarfield toMaskedTagwith mutual exclusivity withregex - Implemented grammar validation in
MaskedTag.__post_init__to ensure proper syntax and prevent reserved rule name conflicts - Updated
build_cfgto handle tags with custom grammars by removing thestart:prefix and embedding the rules
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/gimkit/schemas.py | Added grammar field to MaskedTag dataclass and implemented validation logic including empty string checks, reserved name conflicts, start rule requirement, and syntax validation |
| src/gimkit/dsls.py | Refactored grammar validation into standalone function, added constants for CFG rule naming and docs URL, updated build_cfg to handle tags with custom grammar by stripping start: prefix |
| tests/test_schemas.py | Added tests for grammar validation including empty string, reserved names, missing start rule, and invalid syntax; updated global variable assertions to include grammar field |
| tests/test_dsls.py | Updated test expectations to use new masked_tag_ prefix and added test case for building CFG with custom grammar |
| tests/models/test_utils.py | Updated assertion to expect new masked_tag_ rule naming convention |
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.
Fixes #52