Skip to content

Return tokenizer JSON errors through the C API status contract - #1145

Merged
kunal-vaishnavi merged 1 commit into
mainfrom
user/mustjab/tokenizer-c-api-json-errors
Oct 28, 2026
Merged

kunal-vaishnavi merged 1 commit into
mainfrom
user/mustjab/tokenizer-c-api-json-errors

Conversation

@mustjab

Copy link
Copy Markdown
Contributor

Summary

  • Translate tokenizer JSON exceptions into explicit error codes and error text instead of letting them escape extern-C creation APIs.
  • Share the default/options path and initialize outputs to null on failure; valid loading and tokenization remain unchanged.
  • Add direct blob/file regressions for malformed syntax, invalid JSON types, and output ownership.

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.

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>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 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

@kunal-vaishnavi
kunal-vaishnavi merged commit 208bcc3 into main Oct 28, 2026
37 checks passed
@kunal-vaishnavi
kunal-vaishnavi deleted the user/mustjab/tokenizer-c-api-json-errors branch October 28, 2026 23:11
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.

3 participants