Repository navigation
Fix ValueError on literal special-token strings in TiktokenCounter (#… - #13016
Closed
ramashishmaurya wants to merge 1 commit into
Closed
ramashishmaurya wants to merge 1 commit into
ramashishmaurya wants to merge 1 commit into
Conversation
ramashishmaurya
requested review from
anakin87
and removed request for
a team
September 29, 2026 09:15
Contributor
|
@ramashishmaurya is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
Hi @ramashishmaurya, 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:
TiktokenCounter.count()was previously raising aValueErrorwhen encountering literal tiktoken special-token strings (like<|endoftext|>) inside the conversation or tool schemas. This was because it usedself._encoder.encode()which strictly disallows special tokens by default.This PR replaces
encode()withencode_ordinary()inTiktokenCounter.count(). This ensures that special-token strings are treated as ordinary text and correctly counted, preventing crashes when an agent processes uncontrolled text (e.g., retrieving an OpenAI documentation page).How did you test it?
test_counts_literal_special_tokensintest_tiktoken_counter.pythat verifiesTiktokenCountersuccessfully counts text containing<|endoftext|>without raising an exception.Notes for the reviewer
This fix mirrors the approach taken in
#12853for document splitters.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.