Skip to content

fix(grammar): decode JSON Pointer escapes in schema references - #2368

Open
YaoxinHuang wants to merge 4 commits into
abetlen:mainfrom
YaoxinHuang:fix/json-pointer-reference-escapes
Open

YaoxinHuang wants to merge 4 commits into
abetlen:mainfrom
YaoxinHuang:fix/json-pointer-reference-escapes

Conversation

@YaoxinHuang

Copy link
Copy Markdown

LlamaGrammar.from_json_schema() raises AssertionError for valid references to definition names containing / or ~. For example, {"$defs": {"a/b": {"const": 42}}, "$ref": "#/$defs/a~1b"} fails because the resolver looks up the literal key a~1b.

Decode each JSON Pointer token before looking it up, replacing ~1 before ~0 as required by RFC 6901 section 4. The regression cases cover slash, tilde, combined escapes, and ~01 to catch an incorrect decoding order.

Validation: the new cases fail on the original code; all 10 grammar, chat-format, and speculative tests pass after the fix. Ruff lint and formatting checks pass for llama_cpp and tests. Tested on Windows/Python 3.12 using the current Python source and the official v0.3.35 CPU wheel's native library; the model-dependent inference suite was not run.

Prepared with AI assistance (Codex).

This branch has not been deployed

No deployments
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.

1 participant