Repository navigation
Return tokenizer JSON errors through the C API status contract - #1145
Merged
Merged
Conversation
Contain JSON-domain exceptions inside tokenizer creation entry points instead of propagating them across extern-C calls. Reuse the options creation path, initialize outputs to null, and verify syntax/type failures plus unchanged valid blob/path/lookup/stream behavior. The direct malformed-vocabulary regression fails before the fix and15 targeted native cases pass afterward. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
🔵 Needs a closer look
Native Windows execution of the C API regressions remains pending, so the exception translation has not yet been confirmed to resolve the production crash under MSVC /EHsc.
No open issues 🎉
What changed in this PR
This PR makes tokenizer creation report JSON exceptions through the C API’s error-code and error-message contract, rather than allowing them to escape to callers.
Changes:
- Share the default and options-based creation path and catch JSON exceptions for file and blob loading.
- Validate output pointers and initialize valid outputs to null before loading.
- Document the failure contract and add regressions for malformed JSON, invalid types, and output ownership.
| File | Description |
|---|---|
test/pp_api_test/test_tokenizer_blob.cc |
Adds file/blob JSON failure and output-pointer regression tests. |
shared/api/c_api_tokenizer.cc |
Unifies creation paths and translates JSON exceptions into C API errors. |
include/ortx_tokenizer.h |
Documents JSON error reporting and null outputs on failure. |
Review effort: Balanced
Mustapha Jaber (mustjab)
marked this pull request as ready for review
October 28, 2026 18:41
Mustapha Jaber (mustjab)
requested review from
Baiju Meswani (baijumeswani) and
Sayan Shaw (sayanshaw24)
October 28, 2026 19:10
kunal-vaishnavi
approved these changes
Oct 28, 2026
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
Validation
The direct malformed-vocabulary C API test fails before the fix because a JSON exception escapes. All 15 targeted native creation, parity, option, lookup, and stream tests pass afterward.
Relevant to microsoft/onnxruntime-genai#2800: MSVC /EHsc assumes extern-C calls do not throw. This fixes a reproduced production boundary defect without changing compiler flags, workflows, or GenAI negative assertions. Actual Windows confirmation of the observed crash remains pending.