Structured OpenAI user content-parts are silently dropped by chat_template

#5
by Sahalk7 - opened

Hi K2 team,

During an independent review of the public K2 Horizon artifacts, I found a reproducible chat-template behavior that may be useful to flag.

When a user message uses OpenAI-style content parts:

[{"role": "user",
  "content": [{"type": "text", "text": "UNIQUE_SENTINEL"}]}]

I used two matched controls:

Control 1 — plain user string: preserved

[{"role": "user", "content": "UNIQUE_SENTINEL"}]

Control 2 — identical structured content in the tool branch: preserved

[{"role": "tool",
  "content": [{"type": "text", "text": "UNIQUE_SENTINEL"}]}]

I reproduced the behavior on both distinct K2 Horizon chat-template implementations. In the frozen CPU-only reproduction, the structured-user loss produces no Python warning, logging record, or stderr output. No model weights or inference are required.

I also checked serving-path reachability rather than assuming it: with the pinned vLLM content-format detector used in the reproduction, the K2 templates resolve to openai, so structured content reaches the template rather than being flattened to a string first.

Minimal reproduction:

from transformers import AutoTokenizer

tok = AutoTokenizer.from_pretrained(
    "IFM/K2-Horizon-0.9B",
    trust_remote_code=False
)

S = "UNIQUE_SENTINEL"

plain = [{"role": "user", "content": S}]
parts = [{"role": "user",
          "content": [{"type": "text", "text": S}]}]

print(tok.apply_chat_template(
    plain, tokenize=False, add_generation_prompt=True))

print(tok.apply_chat_template(
    parts, tokenize=False, add_generation_prompt=True))

The first contains the sentinel; the second renders an empty user turn.

I am treating this specifically as a chat-template/integration observation, not a model-quality issue, and I am not making any claim about intent. If structured content is intentionally unsupported for user messages, an explicit error or documentation note may be preferable to silent content loss.

I have a frozen reproduction package with exact template hashes, revisions, captured outputs and the pinned vLLM source if it would be useful.

Thanks,
Sahal AlKubaisi

Institute of Foundation Models org

@junchen01 , what do you think?

Sign up or log in to comment