Skip to content

Conversation

@ochafik
Copy link
Collaborator

@ochafik ochafik commented Dec 15, 2025

Models often output whitespace (newlines, spaces) between XML tags and JSON content, e.g.:

<function=transfer_to_human>
     {"reason": "..."}
</function>

This can cause parsing failures in Hermes 2 Pro (e.g. happened to me w/ unsloth/Qwen3-Coder-30B-A3B-Instruct-1M-GGUF:UD-Q4_K_XL) and other formats because try_consume_json() expected JSON to start immediately at the current position.

Fix by modifying try_consume_json() to:

  • Skip leading whitespace before attempting to parse JSON
  • Consume trailing whitespace after successful JSON parse
  • Restore position if JSON parsing fails (important for streaming)

This fix benefits all chat formats that use try_consume_json().

🤖 Generated with Claude Code

Make sure to read the contributing guidelines before submitting a PR

Models often output whitespace (newlines, spaces) between XML tags and
JSON content, e.g.:

    <function=transfer_to_human>
         {"reason": "..."}
    </function>

This was causing parsing failures in Hermes 2 Pro and other formats
because try_consume_json() expected JSON to start immediately at the
current position.

Fix by modifying try_consume_json() to:
- Skip leading whitespace before attempting to parse JSON
- Consume trailing whitespace after successful JSON parse
- Restore position if JSON parsing fails (important for streaming)

This fix benefits all chat formats that use try_consume_json().

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant