Skip to content

[WIP] Add Mistral guidance#32781

Draft
juliendenize wants to merge 3 commits intovllm-project:mainfrom
juliendenize:add_mistral_grammar
Draft

[WIP] Add Mistral guidance#32781
juliendenize wants to merge 3 commits intovllm-project:mainfrom
juliendenize:add_mistral_grammar

Conversation

@juliendenize
Copy link
Contributor

@juliendenize juliendenize commented Jan 21, 2026

Purpose

This is a work in progress branch to add better guidance for Mistral Tool Parser with the Mistral Tokenizer.

To do so a lark grammar is generated when the --tool-call-parser mistral is used:

  • the lark grammar handles auto, required and none tool choices.
  • naming is also handled by filtering the tools before passing it to the grammar factory.

This PR also brings support for the MistralTokenizer guidance backend.

Test Plan

Right now there are no unit tests attached to the draft PR and has only been checked by manual requests.

Test Result


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with Cloud Agents, enable Autofix in the Cursor dashboard.

Comment @cursor review or bugbot run to trigger another review on this PR

mode = "required"
else:
selected_tools = request.tools
mode = request.tool_choice
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

None tool_choice causes invalid Lark grammar generation

High Severity

When request.tool_choice is None (the default value meaning "auto" behavior), the code sets mode = request.tool_choice, passing None to get_lark_from_jinja. The Jinja template BASE_LARK_GRAMMAR only handles "auto", "required", and "none" string values. When mode is Python None, none of the template conditions match, resulting in an incomplete Lark grammar where the body: rule is never defined but is referenced by start: body. This produces an invalid grammar that will fail during parsing.

Fix in Cursor Fix in Web

@@ -111,9 +291,12 @@ def __init__(self, tokenizer: TokenizerLike):
"Mistral Tool Parser could not locate the tool call token in "
"the tokenizer!"
)
self.grammar_factory = MistralGrammarFactory(tokenizer)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MistralToolParser initialization fails with non-Mistral tokenizers

High Severity

The MistralToolParser.__init__ unconditionally creates MistralGrammarFactory(tokenizer) at line 294, but MistralGrammarFactory requires a MistralTokenizer and raises ValueError for other tokenizer types. This contradicts lines 266-267 which log an info message when a non-Mistral tokenizer is detected, implying this is a supported use case. Any attempt to create MistralToolParser with a non-Mistral tokenizer will now fail during initialization.

Additional Locations (1)

Fix in Cursor Fix in Web

tool
for tool in request.tools
if tool.function.name == request.tool_choice.function.name
]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing validation when named tool doesn't exist in tools list

Medium Severity

When tool_choice specifies a ChatCompletionNamedToolChoiceParam with a function name that doesn't exist in the tools list, selected_tools becomes an empty list. The grammar generation logic treats an empty list as falsy, causing any_strict_true to be False, which generates a permissive grammar allowing any tool name instead of restricting to the specified tool. The user's explicit intent to call a specific tool is silently ignored.

Fix in Cursor Fix in Web

@juliendenize juliendenize changed the title Add Mistral guidance [WIP] Add Mistral guidance Jan 21, 2026
@mergify
Copy link

mergify bot commented Feb 6, 2026

This pull request has merge conflicts that must be resolved before it can be
merged. Please rebase the PR, @juliendenize.

https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify bot added the needs-rebase label Feb 6, 2026
Signed-off-by: Julien Denize <[email protected]>
Signed-off-by: juliendenize <[email protected]>
Signed-off-by: juliendenize <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant