You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Nov 25, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 25, 2026. It is now read-only.
count_tokens.py crashes on text containing special tokens like <|endoftext|> (tiktoken disallowed_special default) #153
count_tokens() in skills/bmad-*-builder/scripts/count_tokens.py guards only import tiktoken and tiktoken.get_encoding(...), then calls enc.encode(text) with tiktoken's default disallowed_special="all". tiktoken raises ValueError ("Encountered text corresponding to disallowed special token '<|endoftext|>'...") when the text contains a special-token string.
Any skill or reference that mentions such a token, for example a skill about tokenizers, prompt formats or LLM evaluation, makes:
count_tokens.py <file> exit with a traceback;
prepass-prompt-metrics.py crash, since it imports count_tokens and calls it on every file, which aborts the Analyze pre-pass.
(The agent-builder prepass.py swallows the exception and silently falls back to chars // 4 for that file.)
This report is from reading the code: the tiktoken encoding download is blocked in my test sandbox, so I couldn't run the tiktoken path. The behaviour is tiktoken's documented default.
Steps to reproduce
printf -- '---\nname: sk\ndescription: Explains tokenizers. Use when asked.\n---\n# sk\n\nModels end documents with the <|endoftext|> marker.\n'> sk/SKILL.md
uv run skills/bmad-workflow-builder/scripts/count_tokens.py sk/SKILL.md
# expected with tiktoken available: ValueError: Encountered text corresponding to disallowed special token '<|endoftext|>'
Expected behavior
Count special-token text as ordinary text: enc.encode(text, disallowed_special=()). Also cache the encoding at module level. Today get_encoding runs per file, and when the encoding can't be downloaded the pre-passes retry the network for every file before falling back, about 0.2 s/file here.
Activity