fix(tokenizer): accept the OpenAI developer role (map to system for templates without it) - #391
Draft
gdevenyi wants to merge 1 commit into
Draft
fix(tokenizer): accept the OpenAI developer role (map to system for templates without it)#391gdevenyi wants to merge 1 commit into
gdevenyi wants to merge 1 commit into
Conversation
…emplates without it) Clients such as pi send the system prompt with role "developer" by default (OpenAI's current spelling of "system"). Most chat templates do not know the role and raise "Unexpected message role", which the server returns as a 400. Map developer to system before rendering unless the template spells the role itself (gpt-oss does). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0173pf9k9fSVtwbm3f898HDt
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 this fixes
A request whose system prompt uses the OpenAI
developerrole (the current spelling ofsystem; pi sends it by default foropenai-completionsproviders,compat.supportsDeveloperRole: true) fails with400 could not encode request: Unexpected message role.on every model whose chat template does not spell the role, which is most of them (Qwen3.8-Flash-Next, Qwen3.x, GLM, ...). The template raises, the server relays it.TokenizeManager._rendernow mapsdevelopertosystembeforeapply_chat_template, unless the template mentionsdeveloperitself (gpt-oss renders the two roles differently and keeps its input). The mapping copies the message; the request is not mutated.Testing
tests/tokenizer/test_tokenize.py::test_developer_role_maps_to_system_unless_the_template_knows_it.{"role": "developer", ...}went from the 400 above to the sameprompt_tokensas thesystemspelling.🤖 Generated with Claude Code
https://claude.ai/code/session_0173pf9k9fSVtwbm3f898HDt