Qwen System Prompt: Format and Practical Examples
Qwen models from Alibaba use the ChatML format for system instructions. Here is the correct structure for Qwen 2.5 and Qwen3, practical examples, and how to test each version.
Updated 4 min read
Qwen models, published by Alibaba Cloud, use the ChatML format for structuring conversations. A system prompt goes in the first turn, wrapped in the same special tokens as every other turn. Getting the format right is essential because a system message in the wrong position or without the correct tokens may be ignored entirely. Tools like fenbs let you store tested Qwen prompts and the lessons from evaluating them, so the next session starts from what worked.
Check the Qwen model cards on Hugging Face (opens in a new tab) and the Qwen documentation (opens in a new tab) for current format details. Qwen releases new versions frequently; format requirements may change between versions.
How Qwen handles system instructions
Qwen models were trained with a chat template that uses three special tokens: <|im_start|>, a role name, and <|im_end|>. The system turn comes first, followed by alternating user and assistant turns. This format is called ChatML, and it is shared by several model families including Hermes models and many Mistral fine-tunes.
When you call a Qwen model through a hosted API (such as Alibaba Cloud DashScope, OpenRouter, or a platform that provides Qwen), the API handles this formatting automatically. When you run Qwen locally through Ollama or a Hugging Face inference pipeline, you need to ensure the template is applied. Most local tools handle this; verify by printing the formatted string before inference.
Message format for Qwen 2.5
Qwen 2.5 models use the standard ChatML format. The system turn is placed at the start of the formatted string. Each turn ends with <|im_end|> and a newline.
<|im_start|>system You are a helpful assistant. Answer in plain English. Be concise.<|im_end|> <|im_start|>user What is a context window in a language model?<|im_end|> <|im_start|>assistant
When using the Hugging Face transformers library, call tokenizer.apply_chat_template() with tokenize=False and add_generation_prompt=True. The tokenizer for Qwen 2.5 models includes the correct template. You do not need to write the tokens manually.
Message format for Qwen3
Qwen3 models, including the 6B parameter size, also use ChatML. One notable addition in Qwen3 is support for a thinking mode, where the model produces explicit reasoning before its final answer. If you are using Qwen3 through a tool that surfaces this feature, your system prompt can include instructions about how much explicit reasoning to show, or none at all.
<|im_start|>system You are a code review assistant. Review the code for correctness and style. Do not show reasoning steps; give your findings directly.<|im_end|> <|im_start|>user [paste code here]<|im_end|> <|im_start|>assistant
For Qwen3 models accessed through an OpenAI-compatible API endpoint, pass the standard messages array with a system role message. The server handles the template conversion. Check the documentation of the specific serving setup for whether thinking mode is configurable through the system prompt or a separate parameter.
Practical examples
Three ready-to-adapt starting points for common Qwen use cases:
<|im_start|>system You are a research assistant. When answering, cite the key points and note any gaps in your knowledge. Use US English. Do not state conclusions you cannot support with evidence.<|im_end|>
<|im_start|>system You are a coding assistant for a TypeScript project. Rules: - Use TypeScript with strict types. No `any`. - Prefer async/await over Promise chains. - Write plain comments only for non-obvious logic. - When asked to explain code, use plain English, not jargon.<|im_end|>
<|im_start|>system Summarize the provided text in three bullet points. Each bullet point should be one sentence. Focus on the main conclusion of each section. Do not add information not present in the text.<|im_end|>
Accessing Qwen through hosted APIs
Alibaba Cloud's DashScope API provides access to Qwen models with an OpenAI-compatible interface. You send a standard messages array with a system role message, and the API handles the ChatML formatting. Other providers including OpenRouter also carry Qwen models with the same interface.
When using a hosted API, you do not need to manage the chat template yourself. The server converts your system message to the ChatML format before sending it to the model. The main thing to verify is that the system role is supported by the model and API version you are using -- check the provider's model documentation.
Testing your prompts
After setting up a system prompt, test it with five varied inputs that cover the main cases your prompt is designed for. Also test at least one edge case: what does the model do when the input is empty, contradicts your instructions, or is in a language you did not specify?
Testing across model sizes is worth the effort if you plan to deploy both a large and a small Qwen model. A 72B model may follow nuanced instructions that a 7B model partially ignores. Simplify the instruction for the smaller model and test again.
A useful verification step: ask the model what its role is or what instructions it has received. A model that correctly read your system prompt will describe your rules. One that did not may give a generic response. This is especially helpful when running a Qwen model locally and you are unsure whether the template was applied.
For the general principles behind writing instructions that hold up, prompt engineering is the reference. System prompt examples has additional patterns to compare.
Save what worked and what failed for each Qwen version
fenbs keeps Lessons learned and Skills alongside your projects. Record which system prompt worked for which Qwen model size and version, what edge cases caused problems, and what you changed. Save the approved prompt as a Skill. When you upgrade to a new Qwen version or try a smaller parameter size, check your Lessons first.
Create a free accountFree for one person · No credit card · Works with Claude, ChatGPT, Cursor and more
How to do this with fenbs
- Create a free account. Start a personal kanban board for your Qwen prompt work.
- Add a task for each prompt you are building. Note the model version, parameter size, and serving environment (Ollama, Hugging Face, API).
- After testing, record the results in the task: what worked, what failed, what you changed.
- Save the approved prompt as a Skill in fenbs. Note the model version and the date you tested it.
- Add a Lesson for any finding worth sharing: a format issue, a behavior difference between model sizes, or an edge case you discovered.
For Qwen-specific usage prompts at the task level (rather than system instructions), prompts for Qwen is the right reference. For how to configure Qwen in a coding environment, system prompt OpenCode covers Qwen model format in that context.