Skip to content

Fix sporadic JSON tool-call detection and add parser hardening for mixed text/tool outputs - #205

Merged
davidkoski merged 1 commit into
ml-explore:mainfrom
aleroot:bare_json_toolcall-fallback
Jun 1, 2026
Merged

davidkoski merged 1 commit into
ml-explore:mainfrom
aleroot:bare_json_toolcall-fallback

Conversation

@aleroot

@aleroot aleroot commented Apr 11, 2026

Copy link
Copy Markdown
Contributor

Proposed changes

This PR fixes sporadic cases where models output raw JSON tool calls (without wrapper tags) and the stream showed raw JSON instead of emitting a toolCall. It also hardens parser behavior to avoid regressions with normal text/JSON and mixed tagged + untagged content.
ToolCallProcessor primarily relied on tagged boundaries for streaming detection. When models (e.g. Qwen2.5 Instruct) occasionally emitted bare JSON tool calls, the content could bypass tool extraction and appear as raw text.

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

JaeminKim-amoz

This comment was marked as spam.

@DePasqualeOrg

Copy link
Copy Markdown
Contributor

I've addressed the parsing problems in this library in Swift LM Response Parser, which parses reasoning and tool-use output from all models implemented in MLX Swift LM and emits a stream of Open Responses events. I created a demo of it in this PR in MLX Swift Examples and submitted a proposal for how it could be used with MLX Swift LM.

If you're able to test it for your use case, please post your feedback here or in an issue in the repo.

@aleroot
aleroot force-pushed the bare_json_toolcall-fallback branch from f12106b to 9d0a255 Compare May 13, 2026 22:13
Comment thread Libraries/MLXLMCommon/Evaluate.swift Resolved
@aleroot
aleroot force-pushed the bare_json_toolcall-fallback branch from d92b72e to c4ff041 Compare May 22, 2026 21:53
Comment thread Libraries/MLXLMCommon/Evaluate.swift Resolved

@davidkoski davidkoski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, but please remove the override in Evaluate -- I think it is not necessary (maybe no longer necessary).

@aleroot
aleroot force-pushed the bare_json_toolcall-fallback branch from 2d84821 to 70e00c8 Compare May 30, 2026 03:14
@aleroot
aleroot force-pushed the bare_json_toolcall-fallback branch from 70e00c8 to 93cdb1d Compare May 30, 2026 03:15
@aleroot

aleroot commented May 31, 2026

Copy link
Copy Markdown
Contributor Author

Looks good, but please remove the override in Evaluate -- I think it is not necessary (maybe no longer necessary).

Updated, let me know if now is good to go. Thanks.

@davidkoski
davidkoski merged commit 1335fb5 into ml-explore:main Jun 1, 2026
2 checks passed
dkgv pushed a commit to dkgv/mlx-swift-lm that referenced this pull request Jul 30, 2026
davidtai pushed a commit to davidtai/mlx-swift-lm that referenced this pull request Oct 6, 2026
…-explore#205)

* fix(mimo): bound vision work by evaluated frames and layers

* Match MiMo media reservations to bounded native working memory
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants