GPT-OSS Improved Chat Template
This repository provides a hardened version of the chat_template.jinja for the GPT-OSS (20B and 120B) models.
The template is based on the Unsloth version and incorporates related optimisations and fixes from both Unsloth and ggml-org.
Beyond these base improvements, this version has been further hardened to eliminate additional corner-case failures.
Specifically, it resolves TypeError crashes caused by the concatenation of null values in the content and thinking fields, and prevents IndexError exceptions occurring from empty tool_calls arrays.
The template includes security checks to prevent token smuggling and prompt injection across all roles. This is active (true) by default but can be disabled via the allow_injection kwarg parameter.
Note: This implementation has only been tested on llama.cpp, but it should work everywhere where the Jinja2 engine supports is string.
Credits and License
This implementation incorporates contributions from OpenAI (original version), Unsloth, ggml-org, Dimon Dev, and Artem Boldariev.
This project is released under the Apache 2.0 License.