Repository navigation
Raise ValueError for empty conversation with continue_final_message in render_jinja_template - #50604
Merged
Rocketknight1 merged 1 commit intoNov 11, 2026
Conversation
…n render_jinja_template
Contributor
|
Thank you for your contribution 🤗! CI Security Gate — waiting for maintainer approvalCI is approved automatically only for authors who already have a contribution merged in this repository. A maintainer will review this PR and approve CI to run on it. |
Rocketknight1
approved these changes
Nov 11, 2026
Rocketknight1
left a comment
Member
There was a problem hiding this comment.
Yeah, makes sense to me! It's an edge case but the fix is small so I'm happy with it
Rocketknight1
enabled auto-merge
November 11, 2026 11:55
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
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.
What does this PR do?
Fixes an uncaught
IndexErrorinrender_jinja_template()whencontinue_final_messageis set and a conversation is an empty list.Problem
In
render_jinja_template(), whencontinue_final_messageis set (truthy), the code accesseschat[-1]to read the final message's continue field. If a conversation is an empty list ([]),chat[-1]raisesIndexError: list index out of rangeinstead of the documentedValueError.The function already raises
ValueErrorfor the case "final message has no continue field" — but it never validates the case "conversation itself is empty", so the empty-list case falls through tochat[-1]and crashes with the wrong exception type.Fix
Add an explicit empty-conversation check at the start of the
if continue_final_message:branch, raisingValueError("continue_final_message is set but the conversation is empty!")— consistent with the existingValueErrorraised for the missing-continue-field case in the same function.Reproducer
continue_final_message=True(bool) reproduces identically — it is normalized to"content"before reachingchat[-1].Dependencies
None.
Who can review?
@ArthurZucker @itazap (tokenizers / chat template)