# How to read/use LLM model templates

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-read-use-llm-model-templates%2F147236%3E%5C
**Category:** Beginners\
**Created:** [March 24, 2025, 9:53pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-read-use-llm-model-templates%2F147236 "2025-03-24T21:53:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jvoid](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@jvoid](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fjvoid)%5C
**Post date:** [March 24, 2025, 9:53pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-read-use-llm-model-templates%2F147236%2F1 "2025-03-24T21:53:23Z")

</div>

Hi guys  
Actually as subject. What are the templates of models. And how actually to read them and to use?

- is it some kind of real go templates or something or is it just an example to grasp the structure idea?
- Are these for parsing/formatting purposes?
- What about the context data (e.g. `.Role`, `.Content`) is it more like to be injected while formatting or placeholders to be scanned?
- Are these quite standardized in language/syntax or fluent for any other model

Thank you

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [March 24, 2025, 11:47pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-read-use-llm-model-templates%2F147236%2F2 "2025-03-24T23:47:39Z")

</div>

The **apply\_chat\_template** function is probably more _primitive_ than you think. It literally just takes a text template and puts it together with the model, and at runtime the tokenizer reads it and converts the OpenAI-style format **list[dict]** to **str**.

I don’t think the OpenAI-style format is standardized in any way, it’s just something that’s convenient to use. To be precise, it’s a little different for each software…  
Well, it’s easy to use.

> **[Templates](https://huggingface.co/docs/transformers/main/chat_templating)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

> **[Chat Completion](https://huggingface.co/docs/api-inference/tasks/chat-completion)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.

> <https://github.com/huggingface/huggingface.js/issues/932>
>
> Hi there!
> 
> OpenAI and HF api seem to have diverged on chat\_completion \`respons…e\_format\`. That of the \[OpenAI\](https://github.com/openai/openai-python/blob/37f5615da1f4360710f6f45920dbb81387d1a4c5/src/openai/types/chat/completion\_create\_params.py#L272) has a \`type\` attribute which takes one of three values \`text\`, \`json\_object\` (free-form JSON generation which isn't in TGI yet) and \`json\_schema\`, and for the last one it has another \`json\_schema\` attribute which itself contains \`name\`, \`schema\`, \`description\` and \`strict\` attributes. 
> 
> On the other hand, HF's \`response\_format: ChatCompletionInputGrammarType\` \[contains\](https://github.com/huggingface/huggingface.js/blob/aeae64e4df999f61f5d872aa78545bd6a486c9a9/packages/tasks/src/tasks/chat-completion/spec/input.json#L228-L261) \`type\` and \`value\` attributes.
> 
> This might break the OpenAI api usability on HF models. Could we have compatibility between these two on this matter? Or does it need probably breaking changes in TGI and huggingface\_hub?
> 
> @Wauplin

---

<div class="post-metadata">

**Author:** ![jvoid](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@jvoid](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fjvoid)%5C
**Post date:** [March 25, 2025, 7:56am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-read-use-llm-model-templates%2F147236%2F3 "2025-03-25T07:56:26Z")

</div>

Ah great. Thanks.  
So it’s just a matter of serialization of structured messages into a text input

Still the question around the standards. It was mentioned in referred docs it uses Jinja as a templater. Yet it seems not all the models follow this as well.  
E.g. Gemmas something go-like style

```auto
{{- range $i, $_ := .Messages }}

```

so how `apply_chat_template` knows how to render them in general?

And regarding input structure it self. Are at least `.messages` `.role` and `.content` are some how basic structure or these could vary as well?

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FJohn6666)%5C
**Post date:** [March 25, 2025, 9:56am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-read-use-llm-model-templates%2F147236%2F4 "2025-03-25T09:56:32Z")

</div>

Even though it is an OpenAI-style format, it is not an OpenAI class. It must be a **list[dict]** with a similar feel…

For more information on the template format, see below.

```py
chat = [
  {"role": "user", "content": "Hello, how are you?"},
  {"role": "assistant", "content": "I'm doing great. How can I help you today?"},
  {"role": "user", "content": "I'd like to show off how chat templating works!"},
]

```

> **[Advanced Usage and Customizing Your Chat Templates](https://huggingface.co/docs/transformers/chat_template_advanced)**
>
> We’re on a journey to advance and democratize artificial intelligence through open source and open science.
