DEV Community

Cover image for ๐“๐ก๐ž ๐‚๐ก๐š๐ญ ๐“๐ž๐ฆ๐ฉ๐ฅ๐š๐ญ๐ž๐ฌ ๐‡๐š๐ง๐๐›๐จ๐จ๐ค: ๐ด ๐ท๐‘’๐‘ฃ๐‘’๐‘™๐‘œ๐‘๐‘’๐‘Ÿ'๐‘  ๐บ๐‘ข๐‘–๐‘‘๐‘’ ๐‘ก๐‘œ ๐ฝ๐‘–๐‘›๐‘—๐‘Ž, ๐‘Ž๐‘๐‘๐‘™๐‘ฆ๐‘โ„Ž๐‘Ž๐‘ก๐‘ก๐‘’๐‘š๐‘๐‘™๐‘Ž๐‘ก๐‘’, ๐‘Ž๐‘›๐‘‘ ๐‘…๐‘’๐‘›๐‘‘๐‘’๐‘Ÿ๐‘–๐‘›๐‘” ๐‘€๐‘œ๐‘‘๐‘’๐‘™-๐‘…๐‘’๐‘Ž๐‘‘๐‘ฆ ๐‘ƒ๐‘Ÿ๐‘œ๐‘š๐‘๐‘ก๐‘ 
Ranjan Kumar
Ranjan Kumar

Posted on

๐“๐ก๐ž ๐‚๐ก๐š๐ญ ๐“๐ž๐ฆ๐ฉ๐ฅ๐š๐ญ๐ž๐ฌ ๐‡๐š๐ง๐๐›๐จ๐จ๐ค: ๐ด ๐ท๐‘’๐‘ฃ๐‘’๐‘™๐‘œ๐‘๐‘’๐‘Ÿ'๐‘  ๐บ๐‘ข๐‘–๐‘‘๐‘’ ๐‘ก๐‘œ ๐ฝ๐‘–๐‘›๐‘—๐‘Ž, ๐‘Ž๐‘๐‘๐‘™๐‘ฆ๐‘โ„Ž๐‘Ž๐‘ก๐‘ก๐‘’๐‘š๐‘๐‘™๐‘Ž๐‘ก๐‘’, ๐‘Ž๐‘›๐‘‘ ๐‘…๐‘’๐‘›๐‘‘๐‘’๐‘Ÿ๐‘–๐‘›๐‘” ๐‘€๐‘œ๐‘‘๐‘’๐‘™-๐‘…๐‘’๐‘Ž๐‘‘๐‘ฆ ๐‘ƒ๐‘Ÿ๐‘œ๐‘š๐‘๐‘ก๐‘ 

Your model passed every benchmark. Then it quietly got worse in production - and nothing in the logs explains why.

The usual culprit isn't the model. It's the chat template: the code that turns your list of messages into the exact tokens the model was trained on. Get it wrong and the model still answers - just worse, silently, with no error to chase.

I wrote a book on that layer.

๐“๐ก๐ž ๐‚๐ก๐š๐ญ ๐“๐ž๐ฆ๐ฉ๐ฅ๐š๐ญ๐ž๐ฌ ๐‡๐š๐ง๐๐›๐จ๐จ๐ค: ๐ด ๐ท๐‘’๐‘ฃ๐‘’๐‘™๐‘œ๐‘๐‘’๐‘Ÿ'๐‘  ๐บ๐‘ข๐‘–๐‘‘๐‘’ ๐‘ก๐‘œ ๐ฝ๐‘–๐‘›๐‘—๐‘Ž, ๐‘Ž๐‘๐‘๐‘™๐‘ฆ๐‘โ„Ž๐‘Ž๐‘ก๐‘ก๐‘’๐‘š๐‘๐‘™๐‘Ž๐‘ก๐‘’, ๐‘Ž๐‘›๐‘‘ ๐‘…๐‘’๐‘›๐‘‘๐‘’๐‘Ÿ๐‘–๐‘›๐‘” ๐‘€๐‘œ๐‘‘๐‘’๐‘™-๐‘…๐‘’๐‘Ž๐‘‘๐‘ฆ ๐‘ƒ๐‘Ÿ๐‘œ๐‘š๐‘๐‘ก๐‘ 

๐ผ๐‘›๐‘ ๐‘–๐‘‘๐‘’: rendering conversations the way the model was actually trained, reading and writing Jinja templates (including the whitespace bugs that silently break tokenization), handling tool-calling, reasoning, and multimodal templates, authoring a correct template for your own fine-tuned model, debugging with golden-token tests in CI, and fixing the cross-engine differences between Transformers, vLLM, and llama.cpp. There's a chapter on the security side too - chat templates are a real, documented inference-time attack surface.

If you ship LLM features, fine-tune open models, or serve them across multiple engines, this is written for you.

LLM #MachineLearning #AIEngineering #OpenSourceAI

Out now on Kindle:
IN: https://www.amazon.in/dp/B0H6STBYWT
US: https://www.amazon.com/dp/B0H6STBYWT

Top comments (0)