Problem
The chat template renderer emits system messages with the role developer instead of system. MessageType::SystemPrompt is annotated #[serde(rename = "developer")], and HuggingFaceChatTemplate::format builds the Jinja context with context!{ role, content }, which serializes the role through serde. So any template that branches on role == 'system' never matches the system message.
Depending on the template, the result is one of:
- the system prompt is silently replaced by the model's built-in default (e.g. Qwen2.5 emits "You are Qwen, created by Alibaba Cloud..." instead of the system message you passed),
- the system message is dropped entirely,
- the render fails with "conversation roles must alternate" (Falcon 7B, Gemma 3, Mistral 7B).
Separately, trim_blocks/lstrip_blocks aren't set on the environment (transformers sets both), and the tojson filter doesn't match Python's json.dumps, so some templates drift on whitespace and on serialized tool/JSON output.
Steps To Reproduce
- Load a chat model whose template special-cases the system role (Qwen2.5, Falcon 7B, Gemma 3, Mistral 7B, ...).
- Build a chat with a system message followed by user/assistant turns.
- Apply the chat template.
- Observe the system content is missing or replaced by a default; for Falcon 7B / Gemma 3 / Mistral 7B the render errors with "conversation roles must alternate".
Expected behavior
System messages render with role system, and the output matches transformers.apply_chat_template(..., tokenize=False) byte-for-byte.
Environment:
- Crate version:
kalosm main
- Rust version: stable
- OS info: Linux
Questionnaire
Problem
The chat template renderer emits system messages with the role
developerinstead ofsystem.MessageType::SystemPromptis annotated#[serde(rename = "developer")], andHuggingFaceChatTemplate::formatbuilds the Jinja context withcontext!{ role, content }, which serializes the role through serde. So any template that branches onrole == 'system'never matches the system message.Depending on the template, the result is one of:
Separately,
trim_blocks/lstrip_blocksaren't set on the environment (transformers sets both), and thetojsonfilter doesn't match Python'sjson.dumps, so some templates drift on whitespace and on serialized tool/JSON output.Steps To Reproduce
Expected behavior
System messages render with role
system, and the output matchestransformers.apply_chat_template(..., tokenize=False)byte-for-byte.Environment:
kalosm mainQuestionnaire