Chat Template

Chat Template transforms structured API messages into a linear stream of tokens with special tags (e.g., <|im_start|>, <|im_end|>).

This has two consequences:

  1. roles cannot be swapped — if the tool result is submitted as a user message, the model will “change the subject” and erase the reasoning chain;
  2. KV Cache is sensitive to the prefix at the token level.

Strategies for handling reasoning history vary: from complete removal (DeepSeek R1) to mandatory return (DeepSeek V4, Claude).

Related: Five components of context, KV Cache