A chat template is a template that defines how a list of conversation messages with roles such as system, user and assistant is converted into the single token string a language model receives as input. Because each model uses different role markers and special tokens, inputs must follow the same format used in training for the model to behave as expected.
Hugging Face's transformers library popularized shipping chat templates written in Jinja syntax inside the tokenizer configuration, and inference engines such as llama.cpp read the same template from GGUF files. Templates also encode constraints such as where a system message may appear and how tool calls are formatted, so a message sequence the model does not support can raise an error.