← All AI resources

AI security · Transformers 5 tokenizer drift guard evaluation guide

Transformers 5 can change prompt-injection guard decisions without changing the weights

A reproducible test found that tokenizer regressions in Transformers 5 changed two open prompt-injection guards, including a fall from 79% detection to 0% on three obfuscations for one public checkpoint mirror.[1][2] Treat the tokenizer and its runtime as part of the security model.

Published by Learnetto team · Published November 29, 2026

Same weights, different input path Version the tokenizer with the guard
Test groupsZero-width · fullwidth · spaced lettersMeasured separately, with 14 injection canaries in each group
Validated pathStored normalizer79% in each group
Changed pathNormalizer skipped0% in each group
Pin artifactsCompare token IDsScore both corporaBlock unexplained drift
The published experiment measured the largest drop on three transformed canary groups for a public Prompt Guard 2 mirror. The result is specific to the tested checkpoints, versions, corpus and threshold.

A November 27 experiment measured two open prompt-injection guards with byte-identical model weights under Transformers 4.57.6 and Transformers 5 releases.[1] The largest change appeared in a public mirror of Llama Prompt Guard 2 86M. Detection of zero-width, fullwidth and spaced-letter variants fell from 79% to 0% in the experiment. A ProtectAI DeBERTa guard changed in both directions: its false-positive rate rose from 9.9% to 13.1%, while fullwidth-canary detection fell from 100% to 86%.[1][2] Open Transformers issues document the underlying normalization regressions, and proposed fixes were still open when this guide was published.[3][4][5][6] The practical response is to version the tokenizer runtime with the guard, compare reference token IDs as well as decisions, and block upgrades when either moves outside an approved tolerance. Model-file hashes alone cannot detect a changed text-to-token path.

Largest measured drop
79% to 0% on 3 obfuscations
False-positive change
9.9% to 13.1% on 680 texts
Weights changed
No, byte-identical model files
Upgrade rule
Test token IDs and decisions

What changed between Transformers 4 and 5

A classifier receives token IDs, rather than raw text. The model weights can remain identical while a library changes how Unicode, whitespace or saved tokenizer stages become those IDs. That is the failure measured in the November 27 guard experiment.[1]

The experiment compared Transformers 4.57.6 with 5.15.0 and 5.24.0. It ran each library version in a separate interpreter, then used one fixed model copy to score every resulting ID sequence. The repository pins model revisions and publishes the canaries, legitimate corpus, scripts and per-row results.[1][2]

Transformers issue 50674 says version 5 can ignore or overwrite normalizers stored in model files. Its affected examples include a public Llama Prompt Guard 2 mirror, ProtectAI's DeBERTa prompt-injection detector and several non-security tokenizers.[4]

A separate DeBERTa issue shows the lower-level mechanism. In the reported Transformers 5 path, the tokenizer loses SentencePiece's precompiled NFKC normalization. Fullwidth letters, ligatures and circled characters then become unknown tokens instead of their normalized forms.[3]

This is narrower than saying Transformers 5 makes every model worse. The documented behavior depends on the tokenizer class and the rules serialized with a checkpoint. Teams need a differential test for the exact checkpoint and dependency pair they deploy.

What the guard experiment found

For the public mirror of Llama Prompt Guard 2 86M, the experiment reported 79% detection for plain injection canaries under Transformers 4.57.6. The same rate also held after zero-width spaces, fullwidth letters or spaces between letters were added because the stored normalizer mapped those variants back to the same IDs.[1][2]

Under the tested Transformers 5 versions, plain-text detection was 71%, while detection for each of those three transformed groups fell from 79% to 0%. Across all 240 canary rows, 38 detections were lost and six were gained. The test also found that 96.6% of 680 legitimate texts received different token sequences, although the measured false-positive rate stayed at zero for this checkpoint.[1][2]

The ProtectAI DeBERTa guard moved differently. Its false-positive rate on the 680 legitimate texts rose from 9.9% to 13.1%, which means 22 additional texts flipped to an alert. Fullwidth-canary detection fell from 100% to 86%, while zero-width-canary detection rose from 86% to 100%.[1][2]

Those mixed results matter. A dependency change can make a guard stricter for one input class and weaker for another. One aggregate accuracy number can hide both the bypass and the extra operational noise.

The reported percentages come from the experiment author, rather than an independent audit of Transformers or the guard vendors. The repository makes the result inspectable and reproducible, but a local reproduction on the checkpoints and hardware used by a team remains the stronger adoption test.[2]

  • Treat every percentage as a result for the published corpus and threshold, rather than an estimate of attack prevalence.[1]
  • Review decision flips row by row. A stable average can conceal a complete failure on one transformation family.
  • Keep legitimate multilingual, code and typography examples beside adversarial canaries so a fix does not trade bypasses for excessive blocking.

Why model hashes and smoke tests miss this failure

A hash of model weights proves that the weight file did not change. It says nothing about the tokenizer code, its native backend, the model's tokenizer.json, SentencePiece data, preprocessing defaults or the IDs sent into the model.

A smoke test with a plain English sentence can also pass while the risky path remains untested. The largest reported Prompt Guard 2 change appeared after invisible characters, compatibility-width characters and inserted spaces altered tokenization. These are exactly the inputs a Unicode-aware security test should preserve.[1]

The same engineering risk applies beyond prompt-injection guards. Embedding models, moderation classifiers, rerankers and structured extractors can all change when a runtime rebuilds a tokenizer differently. The security consequence is highest when a classifier controls access or blocks an action, but the upgrade discipline is useful for every model whose decision threshold matters.

Version labels alone are not enough. Record the model repository and revision, tokenizer artifacts, Transformers version, tokenizers version, Python environment, threshold and any preprocessing that runs before AutoTokenizer. Store the resulting manifest with the evaluation report.

A safe upgrade gate for security classifiers

Run this gate before promoting a Transformers, tokenizers or model revision. Use production preprocessing and the same threshold used by the deployed guard. The goal is to explain every material difference before the new environment receives traffic.

The experiment's direct-file workaround loaded tokenizer.json through the tokenizers library and restored the reference IDs for both tested guards under the tested versions.[1][2] This is evidence for a temporary path, rather than a universal repair. Some checkpoints use SentencePiece rules or class-specific preprocessing that need a different fix, as the open issues show.[3][4]

  • Freeze a reference environment. Export package versions, model revision, tokenizer-file hashes, threshold and preprocessing configuration.
  • Build a compact token probe set. Include ordinary production text, fullwidth characters, zero-width characters, ligatures, combining marks, repeated and trailing whitespace, multilingual text, code and the longest supported input shape.
  • Store reference input IDs for that probe set. In the candidate environment, compare IDs before running the model. Classify every mismatch by tokenizer stage and affected input family.
  • Score a fixed malicious corpus and a fixed legitimate corpus. Report detection, false-positive rate and decision flips by transformation, language and source type.
  • Fail the promotion when an unexplained token mismatch changes a security decision. An accepted change needs an owner, documented reason, new baseline and rollback plan.
  • Canary the accepted build with shadow traffic or a small cohort. Monitor alert volume, bypass canaries, latency and fallback behavior before full rollout.
  • Keep the old environment reproducible until the candidate passes the same deployed checks. A package rollback is useful only when its tokenizer artifacts and model revision remain available.

How to choose a temporary response

Pinning Transformers and tokenizers together is the lowest-change response when the current detector has a trusted baseline. It buys time, but it also postpones other fixes and should have an explicit review date.

Loading tokenizer.json directly may be appropriate when the checkpoint's intended pipeline lives there and the candidate can reproduce the reference IDs. Test padding, truncation, special tokens, batch behavior and save-reload behavior before adopting that path.[1][2]

Applying an unmerged patch increases maintenance responsibility. Pull request 49579 proposes preserving serialized normalizer, pre-tokenizer and decoder stages when a class rebuilds its backend.[5] Pull request 50908 proposes restoring the precompiled SentencePiece normalizer in DeBERTaV2Tokenizer.[6] Both target real failure modes, but neither open proposal should be treated as a released fix until it is merged, released and verified against the deployed checkpoint.

Replacing the guard can reduce dependency risk only if the replacement receives the same adversarial and legitimate-corpus evaluation. A different checkpoint with an untested tokenizer is a transfer of uncertainty, rather than proof of a stronger control.

Limits and unresolved questions

The Prompt Guard 2 result used a public mirror because the official Meta checkpoint is gated. The author states that the mirror is assumed to carry the same files. That assumption should remain visible when interpreting the result.[1][2]

The canary set contains 30 benign instructions, including 14 written as prompt injections, tested under several transformations for 240 rows. One canary is therefore about seven percentage points within a transformation group. A lost detection proves a bypass in the tested setting, but it does not estimate how frequently that input appears in real traffic.[1][2]

The legitimate corpus contains 680 texts from Wikipedia, Python standard-library code and synthetic typography. It is useful for revealing drift, but it cannot represent every language, domain or application distribution.[1][2]

The upstream state can change after publication. Issues 49622 and 50674 and pull requests 49579 and 50908 were open when checked for this guide.[3][4][5][6] Verify the merged commit and released package before removing a pin or changing a workaround.

No prompt-injection classifier is a complete security boundary. Keep tool authorization, least privilege, data isolation, approvals and output validation outside the model so one changed classifier does not create unrestricted access.

Frequently asked questions

  • Does this mean every Transformers 5 tokenizer is broken? No. The public issues identify specific loader and tokenizer-class paths. Differentially test the exact checkpoint you use.[3][4]
  • Can a model hash detect tokenizer drift? No. The experiment kept model weights byte-identical while the runtime produced different token IDs and decisions.[1][2]
  • Should every team downgrade to Transformers 4.57.6? No. Preserve the last validated environment, then test available fixes or workarounds against your own checkpoint and corpus.
  • What is the smallest useful regression test? Store expected IDs and expected decisions for plain text, fullwidth text, a zero-width variant, spaced letters and representative legitimate inputs. Run it on every dependency rebuild.
  • When is an upgrade safe? When token differences are understood, decision changes are accepted against a versioned test set, and the deployment has a monitored rollback path.

Keep learning on Learnetto

Sources

[1] Guard tokenizer drift experiment

[2] Reproduction code, data and results

[3] Transformers DeBERTa normalization issue

[4] Transformers v5 normalization regression tracker

[5] Proposed tokenizer.json pipeline fix

[6] Proposed DeBERTa normalization fix