-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add llguidance grammar support to MaskedTag and update related functionality #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
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 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 |
There was a problem hiding this comment.
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 7 out of 7 changed files in this pull request and generated 1 comment.
Fixes #52