fix: shorten generated tool-call ids to 9 alphanumeric chars (fixes #1375)#1399
Open
u7k4rs6 wants to merge 1 commit into
Open
fix: shorten generated tool-call ids to 9 alphanumeric chars (fixes #1375)#1399u7k4rs6 wants to merge 1 commit into
u7k4rs6 wants to merge 1 commit into
Conversation
Mistral v3 chat templates enforce a 9-character alphanumeric id constraint on tool calls. str(uuid.uuid4()) produces a 36-char hyphenated string that fails this check, causing apply_chat_template to raise on multi-turn tool exchanges and the server to return HTTP 404. Fixes ml-explore#1375
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.
Summary
ToolCallFormatter._formatinserver.pyfalls back tostr(uuid.uuid4())when a tool call has noidfieldstr(uuid.uuid4())is 36 characters with hyphens; Mistral v3 chat templates enforce a 9-character alphanumeric constraint and raiseTemplateErrorwhen this is violatedapply_chat_templateto raise on the second turn of any multi-turn tool exchange with affected models, which the server surfaces as HTTP 404Change
uuid.uuid4().hex[:9]yields 9 lowercase hex characters (e.g.0819261ae) — valid under the Mistral v3 constraint and accepted by all other templates tested.Affected models
mlx-community/Ministral-8B-Instruct-2410-4bit,Mistral-7B-Instruct-v0.3,Mixtral,Mistral-Nemo(any checkpoint sharing the v3 template family).Devstral-Small-2-...-2512is unaffected as its template has no id-length constraint.Closes #1375