Commit c2c37e3
fix: gli_guard and wild_guard both work regardless of transformers major version (#222)
* fix(gli_guard): tolerate list-shaped extra_special_tokens on transformers<5
fastino/gliguard-LLMGuardrails-300M ships tokenizer_config.json's
extra_special_tokens as a list. transformers<5 passes that straight to
_set_model_specific_special_tokens, which assumes a dict and crashes with
AttributeError: 'list' object has no attribute 'keys'. transformers>=5 added
an isinstance(list, tuple) branch that handles this natively.
Shim the same handling for <5, scoped to the one GLiNER2.from_pretrained
call. gliner2's own processor hardcodes and re-injects its special-token
strings by value, never reading these dict keys, so synthesized key names
are safe. Verified against real transformers 4.57.6 and 5.8.0.
Part of #221.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(deps): declare sentencepiece/protobuf in the huggingface extra
allenai/wildguard ships only a raw SentencePiece tokenizer.model (no fast
tokenizer.json). Without sentencepiece + protobuf installed, transformers
can't extract it and misdetects the file as tiktoken-formatted, failing with
"'tiktoken' is required to read a 'tiktoken' file" on every transformers
major version, not just one. Both packages were previously only present
transitively via the gliner extra, so installing huggingface alone left
WildGuard broken.
Verified by reproducing the exact failure (uninstalling both packages) and
the fix (reinstalling them) against real transformers 5.8.0, and separately
against 5.14.1 in an isolated venv — no version gate is needed, this was
never actually a transformers-major-version conflict.
Part of #221.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
* fix(gli_guard): address Copilot review — thread-safety and test brittleness
Serialize _tolerate_list_extra_special_tokens with a module-level lock: it
mutates a class-wide transformers method for its duration, so concurrent
GliGuard() constructions on transformers<5 must not interleave patch/restore.
Rewrite the shim's unit test to simulate transformers<5's dict-only
implementation with a controlled fake instead of relying on the real
installed transformers' _set_model_specific_special_tokens raising
AttributeError on a list — that's an internal detail that could change
upstream independent of the shim's own correctness.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>1 parent 455ec50 commit c2c37e3
3 files changed
Lines changed: 137 additions & 3 deletions
File tree
- src/any_guardrail/guardrails/gli_guard
- tests/unit
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
49 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
50 | 55 | | |
51 | 56 | | |
52 | 57 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
1 | 2 | | |
| 3 | + | |
| 4 | + | |
2 | 5 | | |
3 | 6 | | |
4 | 7 | | |
| |||
59 | 62 | | |
60 | 63 | | |
61 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
62 | 110 | | |
63 | 111 | | |
64 | 112 | | |
| |||
131 | 179 | | |
132 | 180 | | |
133 | 181 | | |
134 | | - | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
135 | 187 | | |
136 | 188 | | |
137 | 189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | | - | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
96 | 173 | | |
97 | 174 | | |
98 | 175 | | |
| |||
0 commit comments