huggingface
type_error
ai_generated
true
ValueError: Text input must of type str (single example), List[str] (batch)
ID: huggingface/wrong-input-type
92%Fix Rate
92%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| any | active | — | — | — |
Root Cause
Tokenizer received wrong input type. Usually passing raw data instead of text strings.
genericWorkarounds
-
95% success Pass correct type: str for single, List[str] for batch
tokenizer('single text') or tokenizer(['text1', 'text2']) -
90% success Use tokenizer with padding and truncation for batches
tokenizer(texts, padding=True, truncation=True, return_tensors='pt')
-
85% success Check the input type before calling tokenizer
Dead Ends
Common approaches that don't work:
-
Convert everything to string with str()
82% fail
str() on a list produces '['text1', 'text2']' which is tokenized as one string, not a batch
-
Wrap single string in a list unconditionally
55% fail
Some pipeline functions handle single strings differently from batches; check the API first