data did not match any variant of untagged enum ModelWrapper (PyPreTokenizerTypeWrapper, PyDecoderWrapper, PyNormalizerTypeWrapper): which tokenizers release reads your tokenizer.json
Exception: data did not match any variant of untagged enum ModelWrapper at line N column 3 means the installed tokenizers could not read the model section of tokenizer.json; PyPreTokenizerTypeWrapper, PyNormalizerTypeWrapper, PyDecoderWrapper and PostProcessorWrapper are the same failure in the pre_tokenizer, normalizer, decoder and post_processor sections. The usual cause in files written since August 2024: tokenizers 0.20.0 and later save BPE merges as pairs (["a", "b"]), and 0.19.1 and earlier read only strings ("a b"). Install tokenizers 0.20.0 or later, which transformers requires from 4.45.0 (4.18.0 to 4.44.2 cap it below 0.20), or rewrite the merges as strings. The line number is where the section ends, not where the problem is.
Which tokenizers release can read my tokenizer.json?
Load the file: the checker lists every component, the releases that read it, the message the others print, and the transformers releases whose requirement allows a release that works. Without the file, paste the error and pick your version.
Examples (trained on nine sentences):
Your version: pip show tokenizers (do not trust tokenizers.__version__ on 0.11.1 to 0.11.5: those five releases report 0.11.0). The checker matches each component against the 342 distinct forms we ran; a combination of fields outside them is reported as not tested instead of guessed.
What does "untagged enum ModelWrapper" mean?
The name after untagged enum tells you which top-level section of tokenizer.json failed to parse, and nothing more. tokenizers tries every type it knows for that section and reports only that none fitted.
| section of tokenizer.json | name in the message (releases that print it) |
|---|---|
model | ModelWrapper (0.9.0 to 0.19.1); ModelUntagged (0.20.0 and later); MergeType (0.20.0 and later) |
pre_tokenizer | PyPreTokenizerTypeWrapper (0.9.0 to 0.21.1); PreTokenizerUntagged (0.21.2 and later) |
normalizer | PyNormalizerTypeWrapper (0.9.0 to 0.21.1); NormalizerUntagged (0.21.2 and later) |
decoder | PyDecoderWrapper (0.9.0 and later) |
post_processor | PostProcessorWrapper (0.9.0 and later) |
The position in the message is the end of that section. In the 18,084 loads on 0.9.0 to 0.23.3, 2,960 errors pointed at the last character of the failing section and 494 at the last character of the file; none pointed at the field that caused it. Model errors are reported at the end of the file from 0.20.0 on, at the end of model before. Since model is the last section tokenizers writes, a file saved with the default pretty layout gives line (last line - 1) column 3 on 0.19.1 and earlier and line (last line) column 1 on 0.20.0 and later.
From 0.20.0 the model section also reports what is wrong instead of this message when the type is known (see the broken-file table); the pre-tokenizer does so from 0.21.2 for a regex that does not compile and for the Metaspace mismatch below.
Which tokenizers version does each tokenizer.json feature need?
These are the first releases that read each form and kept reading it through 0.23.3. "transformers from" is the first transformers release from which every release allows such a tokenizers.
| section | form in the file | tokenizers from | released | transformers from | the release before it says |
|---|---|---|---|---|---|
| model | BPE with merges as pairs: "merges": [["a", "b"], ...] | 0.20.0 | 2024-08-08 | 4.45.0 | data did not match any variant of untagged enum ModelWrapper |
| model | BPE with "ignore_merges" honoured | 0.19.1 | 2024-04-17 | 4.40.0 | loads, field ignored |
| model | BPE with "byte_fallback" honoured | 0.13.3 | 2023-04-05 | 4.23.0 | loads, field ignored |
| model | Unigram with "byte_fallback" honoured | 0.14.0 | 2023-09-07 | 4.34.0 | loads, field ignored |
| normalizer | Prepend | 0.13.3 | 2023-04-05 | 4.23.0 | data did not match any variant of untagged enum PyNormalizerTypeWrapper |
| normalizer | ByteLevel as a normalizer | 0.20.0 | 2024-08-08 | 4.45.0 | data did not match any variant of untagged enum PyNormalizerTypeWrapper |
| normalizer | Replace, Nmt, Precompiled, StripAccents | 0.9.0 | 2020-10-09 | 4.0.0 | – |
| pre_tokenizer | Split | 0.10.0 | 2021-01-12 | 4.3.0 | data did not match any variant of untagged enum PyPreTokenizerTypeWrapper |
| pre_tokenizer | Punctuation with "behavior" | 0.11.0 | 2021-12-23 | 4.16.0 | data did not match any variant of untagged enum PyPreTokenizerTypeWrapper |
| pre_tokenizer | ByteLevel with "use_regex" honoured | 0.12.0 | 2022-03-31 | 4.16.0 | loads, field ignored |
| pre_tokenizer | Metaspace with "prepend_scheme" honoured (file also has "add_prefix_space") | 0.15.0 | 2023-11-14 | 4.35.2 | loads, field ignored |
| pre_tokenizer | Metaspace with "prepend_scheme" and "split", no "add_prefix_space" | 0.19.0 | 2024-04-17 | 4.40.0 | data did not match any variant of untagged enum PyPreTokenizerTypeWrapper |
| pre_tokenizer | FixedLength | 0.21.2 | 2025-06-24 | 4.47.0 | data did not match any variant of untagged enum PyPreTokenizerTypeWrapper |
| decoder | CTC | 0.10.3 | 2021-05-24 | 4.3.0 | data did not match any variant of untagged enum PyDecoderWrapper |
| decoder | Sequence of decoders | 0.13.0 | 2022-09-21 | 4.23.0 | data did not match any variant of untagged enum PyDecoderWrapper |
| decoder | Replace, Fuse, ByteFallback, Strip | 0.13.3 | 2023-04-05 | 4.23.0 | data did not match any variant of untagged enum PyDecoderWrapper |
| decoder | Metaspace with "prepend_scheme" and "split", no "add_prefix_space" | 0.19.0 | 2024-04-17 | 4.40.0 | data did not match any variant of untagged enum PyDecoderWrapper |
| post_processor | Sequence of post-processors | 0.13.0 | 2022-09-21 | 4.23.0 | data did not match any variant of untagged enum PostProcessorWrapper |
| truncation | "direction" honoured | 0.11.1 | 2021-12-28 | 4.16.0 | loads, field ignored |
"Honoured" rows: older releases from 0.9.0 load the file and skip the field, see below. A component inside a Sequence needs both the row for the Sequence and its own row: in 11 Sequences we ran, the Sequence failed exactly where its container or one of its members failed. The last column is what the newest release before it does.
Which transformers versions allow which tokenizers?
transformers declares a tokenizers range and pip keeps tokenizers inside it, so the fix is usually a transformers upgrade: merges written as pairs need transformers 4.45.0 or later.
| transformers | first released | requires tokenizers | releases we ran in that range | reads merges as pairs |
|---|---|---|---|---|
| 4.0.0 to 4.2.2 | 2020-11-30 | ==0.9.4 | 0.9.4 | no |
| 4.3.0 to 4.15.0 | 2021-02-08 | <0.11,>=0.10.1 | 0.10.1, 0.10.2, 0.10.3 | no |
| 4.16.0 to 4.16.2 | 2022-01-27 | !=0.11.3,>=0.10.1 | 0.10.1 to 0.23.3 (35 releases) | only 0.20.0 and later |
| 4.17.0 | 2022-03-03 | !=0.11.3,>=0.11.1 | 0.11.1 to 0.23.3 (31 releases) | only 0.20.0 and later |
| 4.18.0 to 4.22.2 | 2022-04-06 | !=0.11.3,<0.13,>=0.11.1 | 0.11.1, 0.11.2, 0.11.4, 0.11.5, 0.11.6, 0.12.1 | no |
| 4.23.0 to 4.33.3 | 2022-10-10 | !=0.11.3,<0.14,>=0.11.1 | 0.11.1 to 0.13.3 (10 releases) | no |
| 4.34.0 to 4.35.1 | 2023-10-03 | <0.15,>=0.14 | 0.14.0, 0.14.1 | no |
| 4.35.2 to 4.39.3 | 2023-11-15 | <0.19,>=0.14 | 0.14.0, 0.14.1, 0.15.0, 0.15.1, 0.15.2 | no |
| 4.40.0 to 4.44.2 | 2024-04-18 | <0.20,>=0.19 | 0.19.0, 0.19.1 | no |
| 4.45.0 to 4.46.3 | 2024-09-25 | <0.21,>=0.20 | 0.20.0, 0.20.1, 0.20.2, 0.20.3 | yes |
| 4.47.0 to 4.55.4 | 2024-12-05 | <0.22,>=0.21 | 0.21.0, 0.21.1, 0.21.2, 0.21.4 | yes |
| 4.56.0 to 5.15.1 | 2025-08-29 | <=0.23.0,>=0.22.0 | 0.22.0, 0.22.1, 0.22.2 | yes |
| 5.16.0 to 5.26.0 | 2026-08-26 | <0.24.0,>=0.23.1 | 0.23.1, 0.23.2, 0.23.3 | yes |
From the Requires-Dist of each final transformers release on PyPI (2026-12-04). The fourth column lists the releases we ran that the range admits (yanked 0.12.0 and 0.20.4 left out). 4.16.0 to 4.17.0 declare no upper bound, so pip gives them the newest tokenizers that has a wheel for your Python; we did not run transformers itself. transformers before 4.0.0 pinned one exact tokenizers build, some of them release candidates we did not run.
Can a newer tokenizers fail on a file an older one reads?
Yes, in two cases. Of the 181 forms the releases themselves wrote, 0.23.3 rejects only these.
- Metaspace with
"add_prefix_space": falseand no"prepend_scheme": "never". Releases up to 0.14.1 wrote{"type": "Metaspace", "replacement": "▁", "add_prefix_space": false}(0.9.0 to 0.10.1 with one more field,str_rep), and 0.15.0 to 0.15.2 added"prepend_scheme": "always"to it. 0.10.2 to 0.15.2 read both; 0.19.0 and later reject them. As a pre-tokenizer the message isuntagged enum PyPreTokenizerTypeWrapperon 0.19.0 to 0.21.1 andadd_prefix_space does not match declared prepend_schemefrom 0.21.2; as a decoder it isuntagged enum PyDecoderWrapperthrough 0.23.3. Repair: add"prepend_scheme": "never"(keepadd_prefix_space). That form loads in every release from 0.10.2 to 0.23.3, and gave the same tokens and the same decoded text as the old form did on 0.10.2 to 0.15.2. - BPE with a token that contains a space, saved by 0.19.1 or earlier. Merges were written as
"left right", so a merge of"a"and" "became"a "and could not be split again: every release from 0.10.1 rejects the file (untagged enum ModelWrapperup to 0.19.1,Merges text file invalid at line Nfrom 0.20.0). It happens when a BPE is trained with no pre-tokenizer. The checker rebuilds the pairs from the vocab when every line splits in exactly one way, and the result needs 0.20.0 or later; in the BPE we trained without a pre-tokenizer, merge 48 already split two ways, so that file can only be saved again from the tokenizer in memory with 0.20.0 or later, or retrained.
Does an older tokenizers that loads the file give the same tokens?
Not when the file sets a field the release does not know: from 0.9.0, unknown fields are skipped without a warning. One small tokenizer per field, run in every release:
| the file sets | input | honoured from | tokens before | tokens from then on |
|---|---|---|---|---|
BPE "ignore_merges": true | abc | 0.19.1 | a bc | abc |
BPE "byte_fallback": true | aé | 0.13.3 | a <unk> | a <0xC3> <0xA9> |
Unigram "byte_fallback": true | aé | 0.14.0 | a é | a <0xC3> <0xA9> |
ByteLevel pre-tokenizer "use_regex": false | a b | 0.12.0 | a Ġ b | aĠ b |
Metaspace "add_prefix_space": true, "prepend_scheme": "never" | a b | 0.15.0 | ▁a ▁b | a ▁b |
truncation "direction": "Left", max_length 2 | a b c | 0.11.1 | a b | b c |
The checker reports such a release as "reads it, ignores a field" only when the file's value differs from what the old release does anyway (for example ignore_merges: false is harmless).
What if the file itself is broken?
Then no upgrade fixes it, but 0.20.0 or later tells you what is wrong where older releases only say ModelWrapper. Hand-edited or generated files we ran:
| section | what is wrong | 0.19.1 says | 0.23.3 says | 0.23.3 behaviour since |
|---|---|---|---|---|
| model | BPE, merges as strings: a merge names a token that is not in vocab | data did not match any variant of untagged enum ModelWrapper | Token `ab` out of vocabulary | 0.20.0 |
| model | BPE, merges as strings: no vocab key | data did not match any variant of untagged enum ModelWrapper | Missing vocab/merges | 0.20.0 |
| model | BPE, merges as strings: two tokens share an id | loads | loads | 0.9.0 |
| model | BPE, merges as pairs: a merge names a token that is not in vocab | data did not match any variant of untagged enum ModelWrapper | Token `ab` out of vocabulary | 0.20.0 |
| model | BPE, merges as pairs: no vocab key | data did not match any variant of untagged enum ModelWrapper | Missing vocab/merges | 0.20.0 |
| model | BPE, merges as pairs: two tokens share an id | data did not match any variant of untagged enum ModelWrapper | loads | 0.20.0 |
| model | BPE, merges as strings: a line with three parts | data did not match any variant of untagged enum ModelWrapper | Merges text file invalid at line 1 | 0.20.0 |
| model | BPE, merges as strings: a line with one part | data did not match any variant of untagged enum ModelWrapper | Merges text file invalid at line 1 | 0.20.0 |
| model | BPE, merges as pairs: an entry with three parts | data did not match any variant of untagged enum ModelWrapper | data did not match any variant of untagged enum MergeType | 0.20.0 |
| model | empty object | data did not match any variant of untagged enum ModelWrapper | data did not match any variant of untagged enum ModelUntagged | 0.20.0 |
| model | unknown type name | data did not match any variant of untagged enum ModelWrapper | data did not match any variant of untagged enum ModelUntagged | 0.20.0 |
| model | Unigram: unk_id past the end of vocab | data did not match any variant of untagged enum ModelWrapper | Unable to load vocab UnkIdNotInVocabulary | 0.20.0 |
| model | Unigram: a score is null (what NaN becomes in JSON) | data did not match any variant of untagged enum ModelWrapper | invalid type: null, expected f64 | 0.20.0 |
| model | Unigram: empty vocab with unk_id 0 | data did not match any variant of untagged enum ModelWrapper | Unable to load vocab EmptyVocabulary | 0.20.0 |
| model | WordPiece: unk_token is not in vocab | loads | loads | 0.9.0 |
| model | WordLevel: unk_token is not in vocab | loads | loads | 0.9.0 |
| post_processor | TemplateProcessing: a template names a special token that special_tokens lacks | loads | loads | 0.9.0 |
| pre_tokenizer | Split: the regex does not compile | data did not match any variant of untagged enum PyPreTokenizerTypeWrapper | Oniguruma error: end pattern with unmatched parenthesis | 0.21.2 |
| normalizer | Precompiled: charsmap is not a valid blob | data did not match any variant of untagged enum PyNormalizerTypeWrapper | PanicException: Precompiled: Error("Cannot parse precompiled_charsmap", line: 0, column: 0) | 0.20.0 |
The checker finds the vocab, merge and Unigram problems of this table in your file; it does not compile regexes or decode a Precompiled charsmap. Two BPE tokens with the same id load in every release that reads the merges, and the loaded tokenizer keeps one of them (which one differed between two runs of the same release). A WordPiece or WordLevel whose unk_token is not in the vocab loads from 0.9.0; 0.8.0 and 0.8.1 abort the Python process.
Can I convert the file instead of upgrading?
Yes for merges written as pairs, if no token contains a space. The checker does it in the browser; the same in Python:
import json
d = json.load(open("tokenizer.json", encoding="utf-8"))
merges = d["model"]["merges"]
assert all(" " not in a and " " not in b for a, b in merges), "a token contains a space: needs tokenizers>=0.20.0"
d["model"]["merges"] = [a + " " + b for a, b in merges]
json.dump(d, open("tokenizer.old.json", "w", encoding="utf-8"), ensure_ascii=False, indent=2)
We converted three trained files this way (two with the checker's code, one with this script). The byte-level BPE then loaded in 0.9.0 and later, the one with a Prepend normalizer and byte fallback in 0.13.3 and later, and the one with ignore_merges in 0.19.1 and later (0.13.0 to 0.19.0 load it and ignore that field). Every load the checker calls full gave the ids of the original in 0.23.3.
Which releases behave differently from their neighbours?
Four patch releases of 0.11 do; transformers excludes one of them.
- 0.11.1 rejects a
truncationblock without"direction"(missing field `direction`), which is what every release up to 0.11.0 wrote. 0.11.2 and later read it. - 0.11.0 to 0.11.2 reject
{"type": "Punctuation"}without"behavior", which 0.9.0 to 0.10.3 wrote. - 0.11.3 accepts any object as a pre-tokenizer, including an unknown type, and loads several as a different component. transformers has declared
!=0.11.3since 4.16.0. - 0.11.1 to 0.11.5 report
tokenizers.__version__ == "0.11.0".
How was this measured?
Every final tokenizers release on PyPI from 0.8.0 (2020-06-26) to 0.23.3 (2026-10-09) was installed from its wheel (CPython 3.8 up to 0.20.3, 3.12 after) and run on Linux x86_64.
- Forms. In each release we built every component its Python API can build (181 distinct JSON forms across releases), added 207 variants (each boolean flipped, each enumerated value, an
unk_tokenordropoutset, missing keys, empty Sequences) and 23 broken files. Each of the 411 forms was put into that release's own empty tokenizer.json (indent 2) and loaded withTokenizer.from_strin all 46 releases: 18,906 loads. A load counts as "ignores a field" when the release writes the tokenizer back without it. - Whole files. Eight tokenizers were built and saved the normal way (five with 0.23.3, two with 0.19.1, one with 0.14.1; seven of them trained on nine sentences) and five more files were made from them with the repairs on this page. All 13 were loaded with
Tokenizer.from_filein all 46 releases (598 loads). The checker's verdict matched in every case, the predicted message matched character for character, line and column included, in all 283 failures on 0.9.0 and later (0.8.0 and 0.8.1 report a position inside the section, which the checker does not predict), and all 261 loads the checker calls "reads it fully" gave the ids of the release that saved the file for five test strings. - Not covered. Release candidates, the Node and Rust packages, and files from the Hub (not reachable from the machine that ran this; the trained files stand in for them). A file can load and still tokenize differently between releases for reasons other than the file format.
Questions
How do I fix "data did not match any variant of untagged enum ModelWrapper"?
The installed tokenizers could not read the model section of tokenizer.json. In files written since August 2024 the usual reason is that tokenizers 0.20.0 or later saved the BPE merges as pairs, and tokenizers 0.19.1 or earlier reads only strings. Install tokenizers 0.20.0 or later; transformers requires that from 4.45.0, and 4.18.0 to 4.44.2 do not allow it. If the merges are already strings, or the model is not BPE, the file content is wrong: tokenizers 0.20.0 or later names the real problem instead of this message.
What does the line number in an untagged enum error mean?
It is the line where the failing section ends, not the line of the problem. In the 18,084 loads we ran on tokenizers 0.9.0 to 0.23.3, every error that carried a position pointed at the last character of the failing top-level section, or at the last character of the file for model errors on 0.20.0 and later. That is why the message says column 3 for a pretty-printed file read by an older release, and why the line is close to the end of the file.
Which tokenizers version does transformers install?
Each transformers release declares a range. 4.40.0 to 4.44.2 require tokenizers>=0.19,<0.20 and cannot read merges written as pairs; 4.45.0 to 4.46.3 require >=0.20,<0.21; 4.47.0 to 4.55.4 require >=0.21,<0.22. Upgrading tokenizers alone past the range makes pip report a conflict, so upgrade transformers.
Why does a newer tokenizers reject a tokenizer.json that an older one reads?
Two cases in our runs. A Metaspace pre-tokenizer or decoder with add_prefix_space false and no prepend_scheme "never" (written by 0.14.1 and earlier, and by 0.15.x) is rejected by 0.19.0 and later; 0.21.2 and later say "add_prefix_space does not match declared prepend_scheme" for the pre-tokenizer. And a BPE whose tokens contain spaces, saved by 0.19.1 or earlier, is rejected by every release from 0.10.1. Adding "prepend_scheme": "never" repairs the first; the second needs the merges rebuilt as pairs, which is not always possible from the file alone.
Can I make a tokenizer.json from tokenizers 0.20 or later load in an older tokenizers?
Yes when the only obstacle is the merges: rewrite each pair ["a", "b"] as the string "a b". It works only if no token contains a space. The file then loads in 0.19.1 and, where the other components allow, in older releases; in our runs the converted files gave the same ids as the originals. Releases before 0.19.1 load the file but ignore ignore_merges, which changes the tokens when it is true.
An old tokenizers loads the file without an error. Are the tokens the same?
Not always. Releases from 0.9.0 skip fields they do not know. Before 0.19.1 ignore_merges is ignored, before 0.13.3 byte_fallback of BPE, before 0.14.0 byte_fallback of Unigram, before 0.12.0 use_regex of ByteLevel, before 0.15.0 prepend_scheme of Metaspace, and before 0.11.1 the truncation direction. We ran one small tokenizer for each and the tokens changed at exactly those releases.
Sources
- tokenizers on PyPI: the 46 releases installed and run; dates are PyPI upload dates.
- transformers on PyPI: the tokenizers requirement of each release.
- huggingface/tokenizers, the changes behind the boundaries above: #909 merges as pairs and #1595 better serialization errors (0.20.0), #1476 Metaspace refactor (0.19.0), #1504 ignore_merges serialization (0.19.1), #1183 and #1196 byte fallback and the new decoders (0.13.3), #1217 Unigram byte fallback (0.14.0), #1555 ByteLevel normalizer (0.20.0), #1713 FixedLength (0.21.2), #882 and #884 Punctuation deserialization (0.11.3, 0.11.4).
- Reports of the error without a version answer: Hugging Face forum, October 2024, forum, November 2022 (tokenizers 0.13.1), granite-3.1-2b-instruct discussion, December 2024.
The same data as JSON: data.json, licensed CC BY 4.0.
Related: "cannot import name 'X' from 'transformers'" · "cannot import name 'cached_download' from 'huggingface_hub'" · GGUF token ids that differ from Transformers · which Python each ML package installs on.