Fixed: "PipelineException: No mask_token ([MASK]) found on the input"
A Hugging Face fill-mask pipeline stopped with PipelineException: No mask_token ([MASK]) found on the input. The text marked the missing word with <mask>, but this model's mask token is [MASK], so the pipeline found nothing to fill. Writing the text with the tokenizer's own mask_token makes it work with any fill-mask model.
What I Was Doing
I was asking distilbert/distilbert-base-uncased to guess a missing word, in Transformers 5.26.0 on Python 3.14, and checking a mistake that's easy to make: marking the missing word with <mask>, the mask token RoBERTa models use, in a text for this BERT-style model:
from transformers import pipeline
unmasker = pipeline(
"fill-mask",
model="distilbert/distilbert-base-uncased",
revision="12040accade4e8a0f71eabdb258fecc2e7e948be",
)
print(unmasker("The sky is <mask> today.", top_k=3))
uv run python mask_error.py
What I Expected
Three guesses for the missing word, each with its score and the completed sentence.
What I Got
A traceback. Its first lines:
Loading weights: 100%|██████████████████████████████████████████| 105/105 [00:00<00:00, 8412.64it/s]
Traceback (most recent call last):
File "/Users/you/source/fill-mask-demo/mask_error.py", line 9, in <module>
print(unmasker("The sky is <mask> today.", top_k=3))
~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
And its last lines:
File "/Users/you/source/fill-mask-demo/.venv/lib/python3.14/site-packages/transformers/pipelines/fill_mask.py", line 94, in _ensure_exactly_one_mask_token
raise PipelineException(
...<3 lines>...
)
transformers.pipelines.base.PipelineException: No mask_token ([MASK]) found on the input
![The terminal after uv run python mask_error.py: a traceback from the line that calls unmasker with The sky is mask today, through the fill-mask pipeline's preprocess and _ensure_exactly_one_mask_token, ending in transformers.pipelines.base.PipelineException: No mask_token ([MASK]) found on the input.](https://strdewiridedevblogsprod.blob.core.windows.net/images/blog/ai/hugging-face/transformers/fixes/2026/tf-mask-01-error.webp)
The message names the token the pipeline was looking for: [MASK]. My text had <mask>.
What I Checked
How the pipeline looks for the mask. In transformers/pipelines/fill_mask.py, the pipeline searches the tokenized text for the tokenizer's mask token, by its number in the vocabulary, and raises this exception when it finds none:
def get_masked_index(self, input_ids: GenericTensor) -> np.ndarray:
masked_index = torch.nonzero(input_ids == self.tokenizer.mask_token_id, as_tuple=False)
return masked_index
def _ensure_exactly_one_mask_token(self, input_ids: GenericTensor) -> np.ndarray:
masked_index = self.get_masked_index(input_ids)
numel = np.prod(masked_index.shape)
if numel < 1:
raise PipelineException(
"fill-mask",
self.model.base_model_prefix,
f"No mask_token ({self.tokenizer.mask_token}) found on the input",
)
To this tokenizer, <mask> is just ordinary characters, split into ordinary tokens, so none of them is the mask token.
Which mask token each model uses. It depends on how the model was trained. BERT-style models, such as this DistilBERT model and answerdotai/ModernBERT-base, use [MASK]. FacebookAI/roberta-base uses <mask>: it's one of the special tokens in its tokenizer.json. Examples written for one kind of model fail with the other.
Why It Happens
A fill-mask model only knows the one mask token it was trained with. The pipeline looks for exactly that token, and a mask written for another model looks like normal text to it.
The Fix
Don't type the mask token: take it from the pipeline's tokenizer and put it into the text:
from transformers import pipeline
unmasker = pipeline(
"fill-mask",
model="distilbert/distilbert-base-uncased",
revision="12040accade4e8a0f71eabdb258fecc2e7e948be",
)
mask = unmasker.tokenizer.mask_token
for guess in unmasker(f"The sky is {mask} today.", top_k=3):
print(guess["sequence"])

unmasker.tokenizer.mask_tokenis the mask token of the model the pipeline loaded, here[MASK].- The
fbefore the string puts that token where{mask}is, so the same line works with a model whose mask token is<mask>. guess["sequence"]is the sentence with the guess filled in.
After the Fix
uv run python mask_fixed.py
Loading weights: 100%|█████████████████████████████████████████| 105/105 [00:00<00:00, 13979.68it/s]
the sky is visible today.
the sky is blue today.
the sky is clear today.

Three guesses: visible, blue and clear. The sentences are in lowercase because this is an uncased model: its tokenizer_config.json sets "do_lower_case": true. The commands work unchanged in PowerShell.
Common Mistakes
| Mistake | What happens | Do this instead |
|---|---|---|
| Copying an example written for another model | Its mask token may not be your model's | Use unmasker.tokenizer.mask_token |
| Using a model that wasn't trained to fill masks | The pipeline's documentation says it's for "models that have been trained with a masked language modeling objective" | Choose a model listed under the Fill-Mask task on the Hub |
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
No mask_token (<mask>) found on the input | The same mistake the other way round: [MASK] in the text, a model whose mask token is <mask> | Take the token from unmasker.tokenizer.mask_token |
| A text with two masks returns a list of lists | One list of guesses per mask | Loop over the masks, then over each mask's guesses |
FAQ
How do I see a model's mask token without running a pipeline?
Some models list it in their tokenizer files on the Hub: ModernBERT's tokenizer_config.json has "mask_token": "[MASK]". Others don't: this DistilBERT model's tokenizer_config.json holds only do_lower_case and model_max_length, and its tokenizer uses its type's default. Printing unmasker.tokenizer.mask_token works for every model.
Why does the message say [MASK] when my text had <mask>?
It names the token the pipeline was looking for, the model's own mask token, not what your text contained.
Conclusion
PipelineException: No mask_token ([MASK]) found on the input meant the text had no [MASK]: it used <mask>, which is RoBERTa's mask token, not DistilBERT's. Building the text with unmasker.tokenizer.mask_token filled the gap with "visible", "blue" and "clear".
Additional Resources
- FillMaskPipeline — the fill-mask pipeline,
top_kandtargets. - distilbert/distilbert-base-uncased — the model's card.
