Repository navigation
fix: count literal special-token strings in TiktokenCounter - #12874
Closed
hahahahahayesyeseys wants to merge 1 commit into
Closed
hahahahahayesyeseys wants to merge 1 commit into
hahahahahayesyeseys wants to merge 1 commit into
Conversation
hahahahahayesyeseys
requested review from
bogdankostic
and removed request for
a team
September 23, 2026 11:33
Contributor
|
@hahahahahayesyeseys is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
Hi @hahahahahayesyeseys, thanks for your interest in contributing to Haystack! 🙏 This is an automated message to help us keep the review queue healthy. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related Issues
<|endoftext|>#12869Proposed Changes:
TiktokenCounterpassed rendered messages and tool schemas totiktoken.Encoding.encode(). That method rejects literal special-token strings such as<|endoftext|>by default, even though Haystack treats the rendered input as ordinary user-controlled text. As a result, Agent compaction could fail while counting retrieved content or tool output that merely documents one of those markers.This change uses
encode_ordinary()for the rendered text, matching the behavior already adopted by Haystack's token-based document splitters. It also:There is no public API or serialization change. Inputs that were already accepted keep the same ordinary-text tokenization; literal marker strings now return a count instead of raising
ValueError.How did you test it?
ValueError: Encountered text corresponding to disallowed special token '<|endoftext|>'.17with the realo200k_baseencoder.hatch run test:all test/token_counters/test_tiktoken_counter.py -q --tb=short: 14 passed.hatch run test:all test/token_counters -q --tb=short: 46 passed, 1 skipped becauseOPENAI_API_KEYwas not set.hatch run test:types haystack/token_counters/tiktoken_counter.py test/token_counters/test_tiktoken_counter.py: passed.hatch run fmt-check haystack/token_counters/tiktoken_counter.py test/token_counters/test_tiktoken_counter.py: passed.Notes for the reviewer
The behavioral change is limited to the tiktoken counter's handling of literal special-token text.
encode_ordinary()does not enable special-token semantics; it counts the marker's characters as ordinary text. Non-text image and file charges are unchanged.This contribution was generated with AI assistance. The final diff was reviewed before publication, and the listed tests and checks were executed locally.
Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.