Repository navigation
[WIP] Implement grammar-constrained generation for structured output - #245
Merged
Merged
Conversation
Co-authored-by: makr-code <[email protected]>
Co-authored-by: makr-code <[email protected]>
…pling Co-authored-by: makr-code <[email protected]>
Co-authored-by: makr-code <[email protected]>
Co-authored-by: makr-code <[email protected]>
Co-authored-by: makr-code <[email protected]>
Co-authored-by: makr-code <[email protected]>
Co-authored-by: makr-code <[email protected]>
10 tasks
7 of 25 tasks
7 tasks done
Copilot AI
added a commit
that referenced
this pull request
May 5, 2026
…oid, self-consistency) Agent-Logs-Url: https://github.com/makr-code/ThemisDB/sessions/17b97ffe-2d15-4d81-bfe5-cb887b80a165 Co-authored-by: makr-code <[email protected]>
12 of 56 tasks
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.
Thanks for assigning this issue to me. I'm starting to work on it and will keep this PR's description up to date as I form a plan and make progress.
Original prompt
This section details on the original issue you should resolve
<issue_title>05-implement-grammar-constraints.md</issue_title>
<issue_description>---
name: "🟢 Implement Grammar-Constrained Generation (Phase 3.2)"
about: Guarantee valid JSON/XML/structured output using EBNF grammars
title: "[P2] Implement Grammar-Constrained Generation - Guaranteed Structured Output"
labels: ["priority: medium", "type: feature", "component: llm", "phase-3"]
assignees: []
Priority
🟢 MEDIUM - P2 (Phase 3, high value feature)
Overview
Implement grammar-constrained generation to guarantee valid structured output (JSON, XML, custom formats) using EBNF grammars, eliminating parsing errors and retry logic.
Impact:
Depends On
Documentation
📄 Complete implementation guide available:
docs/en/llm/GRAMMAR_CONSTRAINED_GENERATION.md(12.8KB)Feature Requirements
Built-in Grammars
Provide ready-to-use grammars for common formats:
Custom Grammar Support
Allow users to define custom EBNF grammars:
Implementation Tasks
1. Grammar Infrastructure (include/llm/grammar.h)
Create Grammar class
Add GrammarCache for compiled grammars
2. Built-in Grammars (src/llm/grammars/)
Create grammar files:
json_strict.ebnf- Strict JSONjson_relaxed.ebnf- JSON with trailing commas, etc.xml.ebnf- XML formatcsv.ebnf- CSV formatreact_agent.ebnf- ReAct agent formatEmbed grammars in binary (CMake resource compilation)
3. LlamaWrapper Integration (src/llm/llama_wrapper.{h,cpp})
Add generateConstrained() method
Implement token sampling with grammar
Add configuration support
4. Configuration Files
Update
config/llm_config.example.yamlUpdate
config/llm_config.production.yaml5. HTTP API Integration
Add grammar parameter to generate endpoint
Support custom grammar upload
6. CLI Interface
Add
--grammarflagthemisdb llm generate \ --prompt "Generate JSON user data" \ --grammar json \ --model mistral-7bAdd
--grammar-fileflagthemisdb llm generate \ --prompt "Plan action" \ --grammar-file /grammars/agent.ebnf \ --model mistral-7b7. Testing
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.