[GH-ISSUE #11911] Please allow us to pass through GBNF directly to llama.cpp #54419

Closed
opened 2026-04-29 05:55:07 -05:00 by GiteaMirror · 3 comments
Owner

Originally created by @nicholas-johnson-techxcel on GitHub (Aug 15, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/11911

This would give us incredible control over the output.

For JSON output, Pydantic could be modified to output GBNF directly, for better accuracy and to skip the complexities of JSON schemas.

But generally, GBNF allows many more possibilities, allowing us to force the natural language output to respond with given tones and phrasing without having to prompt the model.

I do not believe it would be hard to pass this through - just the format parameter allowed to be None | 'json' | JSONSchema | GBNF.

Thanks for your consideration.

Originally created by @nicholas-johnson-techxcel on GitHub (Aug 15, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/11911 This would give us incredible control over the output. For JSON output, Pydantic could be modified to output GBNF directly, for better accuracy and to skip the complexities of JSON schemas. But generally, GBNF allows many more possibilities, allowing us to force the natural language output to respond with given tones and phrasing without having to prompt the model. I do not believe it would be hard to pass this through - just the `format` parameter allowed to be `None | 'json' | JSONSchema | GBNF`. Thanks for your consideration.
GiteaMirror added the feature request label 2026-04-29 05:55:07 -05:00
Author
Owner

@rick-github commented on GitHub (Aug 15, 2025):

#5899

<!-- gh-comment-id:3192385140 --> @rick-github commented on GitHub (Aug 15, 2025): #5899
Author
Owner

@sjsone commented on GitHub (Aug 23, 2025):

@nicholas-johnson-techxcel I will try to come up with a merge request for this as I would like to have this feature as well.

Due to the multi-model nature of ollama my current plan is to add an optional grammar parameter to the requests that needs to be set if the format is set to GBNF.
Maybe the feature is behind a feature flag (environment variable like OLLAMA_ALLOW_GRAMMAR=1)

That being said the maintainers are a bit resilient to the idea of user supplied grammar files so I cannot guarantee for anything

<!-- gh-comment-id:3217177533 --> @sjsone commented on GitHub (Aug 23, 2025): @nicholas-johnson-techxcel I will try to come up with a merge request for this as I would like to have this feature as well. Due to the multi-model nature of ollama my current plan is to add an optional `grammar` parameter to the requests that needs to be set if the `format` is set to `GBNF`. Maybe the feature is behind a feature flag (environment variable like `OLLAMA_ALLOW_GRAMMAR=1`) That being said the maintainers are a bit resilient to the idea of user supplied grammar files so I cannot guarantee for anything
Author
Owner

@sjsone commented on GitHub (Aug 23, 2025):

@nicholas-johnson-techxcel I created a MR if you want to try it out https://github.com/ollama/ollama/pull/12055

<!-- gh-comment-id:3217366818 --> @sjsone commented on GitHub (Aug 23, 2025): @nicholas-johnson-techxcel I created a MR if you want to try it out https://github.com/ollama/ollama/pull/12055
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#54419