[KongchangAI]
· 1 min read· 865 words

How Chat Templates Shape an LLM's Self-Identity

How Chat Templates Shape an LLM's Self-Identity

Chat templates are implicit instructions that shape how an LLM identifies itself and behaves.

The same LLM can refer to itself in completely different ways — from 'as a language model' to 'as an AI assistant' or no self-qualifier at all — simply by switching chat templates. This happens because models deeply associate specific format tokens with specific behavioral patterns during training. For developers, this means swapping templates isn't just a formatting decision: it affects output style consistency, safety guardrail behavior, and the reproducibility of cross-model evaluations. The key takeaway is that input format is an implicit instruction, just as important as the system prompt itself.

An Overlooked Detail: How Models Refer to Themselves

Large language models (LLMs) frequently open responses with phrases like "As a language model..." — a signature line that many people now associate with AI-generated content. But a discussion on Hacker News (21 upvotes, 7 comments) pointed to a deeper and more interesting phenomenon: a model's "self-identity" is not fixed. It shifts depending on which chat template is applied.

In other words, the same underlying model weights can refer to itself in entirely different ways depending on the conversation format template used — sometimes calling itself a "language model," other times an assistant, an AI, or some other persona entirely. This reveals a mechanism in LLM deployment that developers consistently underestimate.

hackernews source: "As a Language Model": Chat Template Switches LLM Self-Referential Voice

What Is a Chat Template

A chat template is the formatting framework used to structure a conversation before it is fed into a model. It defines how the system prompt, user messages, and assistant replies are assembled into an input sequence the model can process. Different model families — such as Llama, Qwen, and ChatGLM — use different special tokens and role labels to delineate these sections.

The role of a template goes far beyond "formatting." At inference time, it effectively tells the model: "You are currently in a conversation, and you are playing the role of an assistant." When a template implicitly or explicitly encodes an identity for the model, the way that model refers to itself in its responses changes accordingly.

Why Templates Influence Self-Reference

During training, models are exposed to large volumes of conversation data organized in specific formats. The role labels within those formats — such as <|assistant|> or [INST] — become tightly coupled with the self-referential patterns learned from the training corpus. When the template used at inference time matches the one used during training, the model naturally reproduces the self-description it learned. When the template structure shifts, the model's sense of "who it is" shifts with it.

This explains why some developers discover that simply changing the conversation template causes a model to switch from saying "as an AI assistant" to "as a language model" — or to drop self-qualifying disclaimers altogether.

Consider a few mainstream formats: Llama 2 wraps user messages in [INST]...[/INST] and injects system prompts inside a <<SYS>> block at the start; Llama 3 uses special tokens like <|begin_of_text|>, <|user|>, and <|assistant|>; the Qwen series adopts ChatML format, beginning with <|im_start|>system; early ChatGLM versions used an entirely different [Round 1]-style dialogue separator. These differences are not merely symbolic. They are repeated extensively during pretraining and instruction fine-tuning, causing the model to deeply associate specific formats with specific behavioral patterns. As a result, even with identical model weights, applying different templates via HuggingFace transformers' tokenizer.apply_chat_template() fundamentally changes the semantic context the model perceives.

What This Means for Developers

This seemingly minor phenomenon has several direct implications for real-world LLM deployments:

Output style consistency. If a team casually modifies or uses a chat template that doesn't match the model's training format, they may inadvertently alter the model's tone and self-positioning, leading to inconsistent product experiences.

Relevance to jailbreaking and safety boundaries. A model's "as a language model" phrasing often accompanies safety disclaimers. When template switching weakens this self-referential framing, it may indirectly affect how readily the model triggers its safety guardrails — an area worth attention in security research.

Reproducibility of benchmark results. When comparing models without strictly unifying the chat template, observed differences in "personality" or "style" may not reflect the models themselves — they may be artifacts of template variation.

This issue is especially common in local deployment scenarios using inference frameworks like Ollama, llama.cpp, or vLLM. These tools allow users to specify or override chat templates, and many users are unaware that the GGUF or safetensors model files they're using already embed an officially recommended template configuration. When a framework's default template doesn't match the format used during the model's training, model behavior can drift in ways that are difficult to detect — not just in self-reference, but also in refusal thresholds, response verbosity, and how multi-turn context is interpreted. The basic debugging step for this class of issue is to confirm the official chat template from the HuggingFace model page or tokenizer_config.json, then compare it character by character against the format being used in deployment.

A Reminder: Format Is Behavior

The core insight from this discussion is that for LLMs, the input format is itself a form of implicit instruction. Developers tend to focus on the wording of their system prompts while overlooking the fact that the template structure carrying those prompts is equally responsible for shaping model behavior.

For teams that need precise control over model outputs, using the officially recommended chat template — one that matches the model's training — and keeping that template consistent across any fine-tuning experiments is a foundational requirement for reliable results. This small shift in "self-reference" turns out to be an excellent window into how profoundly model behavior can be driven by format.

(Note: This article is based on a brief Hacker News discussion. The original thread was limited in technical detail; some inferences here are reasonable extensions based on general LLM principles.)

#chat template#LLM self-identity#language model behavior#system prompt#inference format#model deployment#tokenizer apply_chat_template#LLM output consistency
Share:

Related articles