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.

ChatML format for Qwen 2.5
<|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.

ChatML format for Qwen3 with thinking mode disabled
<|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:

Research assistant
<|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|>
Code generation assistant
<|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|>
Summarization assistant
<|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.

How fenbs helps

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 account

Free for one person · No credit card · Works with Claude, ChatGPT, Cursor and more

How to do this with fenbs

  1. Create a free account. Start a personal kanban board for your Qwen prompt work.
  2. Add a task for each prompt you are building. Note the model version, parameter size, and serving environment (Ollama, Hugging Face, API).
  3. After testing, record the results in the task: what worked, what failed, what you changed.
  4. Save the approved prompt as a Skill in fenbs. Note the model version and the date you tested it.
  5. 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.

Questions people ask.

What format does Qwen use for system prompts?

Qwen models use the ChatML format with special im_start and im_end tokens around each turn. The system turn comes first. When using a hosted API or a tool like Ollama, the format is applied automatically.

Does Qwen3 handle system prompts differently from Qwen 2.5?

The base ChatML format is the same. Qwen3 adds thinking mode, which changes how the model presents its reasoning. Your system prompt can include instructions about whether to show reasoning steps, depending on how the serving environment exposes that feature.

Can I use the OpenAI API format with Qwen?

Yes, if you are accessing Qwen through a server that provides an OpenAI-compatible endpoint (such as Alibaba Cloud DashScope or vLLM). Pass messages in the standard format with a system role. The server handles the ChatML conversion.

Why is my Qwen model ignoring the system prompt?

The most likely cause is incorrect chat template application. Print the formatted string before inference and check that the system turn appears with the correct im_start and im_end tokens. Also check that add_generation_prompt=True is set when using apply_chat_template().

Does system prompt quality matter more for smaller Qwen models?

Yes. Smaller models are more sensitive to instruction clarity. A nuanced rule that a large model handles gracefully may be partially ignored by a 7B model. Test with your specific model size and simplify instructions if the smaller model does not follow them.

Start with one thing.

Free for one person · No credit card · Works with Claude, ChatGPT, Cursor and more

There is nothing to set up first. Write one line and you’ve started.