Qwen Prompt Engineering Guide
Getting great results from Qwen AI isn't just about what you ask — it's about how you ask it. Whether you're using Qwen 3.5 for complex reasoning, Qwen Coder for development, or Qwen Chat for everyday tasks, the quality of your prompts directly determines the quality of your output.
This guide covers prompt engineering fundamentals, practical templates for common tasks, and advanced techniques like thinking mode and system prompts — everything you need to get the most out of Qwen models.
- Prompt Engineering Fundamentals
- Using Thinking Mode
- System Prompts
- Coding Prompts
- Writing & Content Prompts
- Analysis & Research Prompts
- Multimodal Prompts
- Agentic & Tool-Use Prompts
- Sampling Parameters
- Common Mistakes to Avoid
Prompt Engineering Fundamentals
Prompt engineering is the practice of crafting inputs that guide AI models toward the output you want. With Qwen models, a few core principles make a massive difference:
1. Be Specific and Explicit
Vague prompts produce vague results. The more context and constraints you provide, the better Qwen can deliver.
| Weak Prompt | Strong Prompt |
|---|---|
| Write about AI | Write a 500-word overview of how mixture-of-experts architecture improves LLM efficiency, aimed at software engineers with basic ML knowledge |
| Fix my code | This Python function returns None instead of the expected dictionary. The input is a JSON string. Identify the bug and explain the fix |
| Translate this | Translate the following marketing copy from English to Spanish (Latin American), keeping a casual and engaging tone suitable for social media |
2. Assign a Role
Giving Qwen a specific persona or expertise level dramatically improves output quality. This works because it activates relevant knowledge patterns in the model.
You are a senior Python developer with 10 years of experience in building
REST APIs with FastAPI. Review the following code for security vulnerabilities,
performance issues, and adherence to best practices.
3. Use Structured Formats
Request specific output formats when you need structured results:
- Markdown tables for comparisons
- Numbered lists for step-by-step processes
- JSON/YAML for data that will be parsed programmatically
- Code blocks with language specification for development tasks
4. Provide Examples (Few-Shot Prompting)
Including 1-3 examples of the desired input→output pattern is one of the most effective techniques, especially for formatting or classification tasks:
Classify the following customer messages as "billing", "technical", or "general".
Examples:
- "I was charged twice this month" → billing
- "The app crashes when I open settings" → technical
- "What are your business hours?" → general
Now classify:
- "My payment didn't go through"
- "How do I export my data?"
5. Chain of Thought
For complex reasoning, ask Qwen to show its work. Phrases like "think step by step," "explain your reasoning," or "break this down" significantly improve accuracy on math, logic, and multi-step problems.
Using Thinking Mode
Qwen 3 and Qwen 3.5 support thinking mode — an extended reasoning capability where the model works through problems internally before giving its final answer. This is especially powerful for:
- Complex math and logic problems
- Multi-step coding tasks
- Strategic planning and analysis
- Tasks requiring careful evaluation of trade-offs
How to Enable Thinking Mode
When using the API, add enable_thinking: true to your request. You can also set a thinking_budget to control how much reasoning the model does:
# API example
{
"model": "qwen3.5",
"messages": [{"role": "user", "content": "Your prompt here"}],
"extra_body": {
"enable_thinking": true,
"thinking_budget": 10000
}
}
In Qwen Chat, thinking mode is available as a toggle in the interface. For simpler tasks, you can leave it off to get faster responses.
When to Use Thinking Mode
| Use Thinking Mode | Skip Thinking Mode |
|---|---|
| Solving math/logic puzzles | Simple Q&A and factual lookups |
| Debugging complex code | Text formatting and translation |
| Analyzing pros and cons | Creative writing (unless highly structured) |
| Multi-step planning | Casual conversation |
| Tasks requiring accuracy over speed | Tasks requiring speed over depth |
System Prompts
System prompts set the context, behavior, and constraints for the entire conversation. They're the most powerful tool for shaping how Qwen responds, and they persist across all messages in a session.
Effective System Prompt Template
You are [ROLE] with expertise in [DOMAIN].
## Your Task
[What the model should do]
## Rules
- [Constraint 1]
- [Constraint 2]
- [Output format requirement]
## Context
[Background information the model needs]
System Prompt Example: Technical Writer
You are a senior technical writer for a developer documentation site.
## Your Task
Convert rough technical notes into clear, well-structured documentation pages.
## Rules
- Use simple, direct language (avoid jargon unless defining it)
- Include code examples for every concept
- Structure with H2 for main sections, H3 for subsections
- Add a "Quick Start" section at the top of every page
- Flag any ambiguous or incomplete information with [NEEDS REVIEW]
## Context
The audience is intermediate developers familiar with Python and REST APIs
but new to our specific platform.
Coding Prompts
Qwen Coder and Qwen 3.5 are excellent at coding tasks. Here are prompt patterns that get the best results:
Code Generation
Write a Python function that [specific task].
Requirements:
- Input: [describe input type and format]
- Output: [describe expected output]
- Handle edge cases: [list them]
- Use [library/framework] version [X]
Include type hints and a docstring with usage examples.
Code Review
Review the following [language] code for:
1. Security vulnerabilities (especially [injection type, auth issues, etc.])
2. Performance bottlenecks
3. Code style and readability
4. Error handling gaps
For each issue found, explain the problem and provide a corrected version.
[paste code]
Debugging
This [language] code produces [actual behavior] instead of [expected behavior].
Environment: [language version, OS, relevant dependencies]
Error message (if any): [paste error]
[paste code]
Identify the root cause and provide a fix with explanation.
Writing & Content Prompts
Blog Post / Article
Write a [length]-word article about [topic].
Audience: [who will read this]
Tone: [professional / casual / academic / conversational]
Goal: [inform / persuade / entertain / educate]
Structure:
- Hook opening that [specific approach]
- [Number] main sections with H2 headings
- Practical examples or data points in each section
- Actionable conclusion with [CTA type]
Keywords to include naturally: [list]
Email / Professional Communication
Write a [type: cold outreach / follow-up / announcement] email.
Context: [situation]
Sender: [role and company]
Recipient: [role and relationship]
Goal: [what you want them to do]
Tone: [professional but warm / formal / casual]
Length: [short (3-4 sentences) / medium / detailed]
Analysis & Research Prompts
Data Analysis
Analyze the following [data type] and provide:
1. Key patterns and trends
2. Notable outliers or anomalies
3. Actionable insights
4. Limitations of the analysis
Present findings in a structured format with bullet points.
Include relevant calculations where applicable.
[paste data or describe dataset]
Comparative Analysis
Compare [Option A] vs [Option B] for [specific use case].
Evaluate on these criteria:
- [Criterion 1]
- [Criterion 2]
- [Criterion 3]
For each criterion, provide a brief assessment and rating (1-5).
End with a clear recommendation and reasoning.
For deep reasoning tasks like research analysis, enable thinking mode and use QwQ or Qwen 3.5 for best results.
Multimodal Prompts
Qwen's multimodal models — Qwen Vision, Qwen Audio, and Qwen Omni — accept images, audio, and video as input. Effective multimodal prompting follows the same principles but adds visual/audio context:
Image Analysis
[Attach image]
Analyze this image and provide:
1. A detailed description of what's shown
2. Any text or data visible in the image
3. [Specific question about the image]
If this is a chart/graph, extract the key data points and trends.
Document Processing
[Attach document image / PDF page]
Extract all information from this [invoice / receipt / form / table]
into a structured JSON format. Include:
- All visible fields and values
- Any handwritten annotations
- Flag any fields that are unclear with "UNCERTAIN"
Agentic & Tool-Use Prompts
Qwen 3.5 excels at agentic workflows — tasks where the model needs to plan, use tools, and execute multi-step processes. When building agentic systems:
Key Principles for Agentic Prompts
- Define available tools clearly — describe each tool's purpose, parameters, and expected output
- Set explicit goals — what does "done" look like?
- Include error handling instructions — what should happen when a tool fails?
- Limit scope — constrain what the agent can and cannot do
You are an AI assistant with access to the following tools:
- search(query): Search the web and return top 5 results
- read_page(url): Read the content of a webpage
- calculate(expression): Evaluate a math expression
## Task
Research [topic] and provide a comprehensive summary with sources.
## Process
1. Search for the most relevant and recent information
2. Read the top 2-3 sources
3. Synthesize findings into a structured summary
4. Cite all sources with URLs
## Constraints
- Only use information from sources you've actually read
- If conflicting information is found, note the discrepancy
- Maximum 3 search queries
Sampling Parameters
Beyond prompt text, you can tune Qwen's behavior with sampling parameters. Here's what each one does:
| Parameter | Range | Effect | Recommended For |
|---|---|---|---|
| Temperature | 0.0 – 2.0 | Controls randomness. Lower = more deterministic, higher = more creative | 0.0–0.3 for code/math, 0.7–1.0 for creative writing |
| Top-p | 0.0 – 1.0 | Nucleus sampling. Considers tokens whose cumulative probability reaches this threshold | 0.9 for most tasks, 0.5–0.7 for focused outputs |
| Top-k | 1 – ∞ | Limits to top K most likely tokens at each step | 50 for general use, 10–20 for more focused output |
| Max tokens | 1 – model limit | Maximum length of the generated response | Set based on expected output length |
| Repetition penalty | 1.0 – 2.0 | Penalizes repeated tokens. Higher = less repetition | 1.05–1.1 for long-form content |
| Presence penalty | -2.0 – 2.0 | Encourages discussing new topics | 0.5–1.0 for diverse, exploratory responses |
Parameter Presets
- Coding / factual tasks: temperature=0.0, top_p=0.9
- General assistant: temperature=0.7, top_p=0.9
- Creative writing: temperature=0.9, top_p=0.95, presence_penalty=0.5
- Brainstorming: temperature=1.2, top_p=0.95, presence_penalty=1.0
Common Mistakes to Avoid
- Being too vague — "Help me with my project" gives the model nothing to work with. Specify what, why, and how.
- Overloading a single prompt — Break complex tasks into steps. Ask Qwen to plan first, then execute each part.
- Ignoring context limits — Very long prompts with irrelevant information dilute quality. Include only what's necessary.
- Not iterating — Your first prompt rarely produces the perfect result. Refine based on what you get back.
- Skipping system prompts — For API users, a well-crafted system prompt eliminates repetition across messages.
- Using thinking mode for simple tasks — It adds latency without benefit for straightforward requests. Save it for complex reasoning.
Get Started
Ready to put these techniques into practice? Here are the best ways to start:
Try Qwen Chat
The easiest way to experiment with prompts — no setup required.
Qwen 3.5 Overview
Learn about the latest and most capable Qwen model.
Qwen Coder
Specialized model for coding prompts and development tasks.
Use Cases
See real-world applications and find the right model for your task.