Prompt Engineering with Qwen3 for Structured Output (JSON, Tables, Markdown)

Prompt Engineering with Qwen3 for Structured Output

Introduction: Control the Shape of Qwen3’s Responses

When building AI agents, tools, or apps with Qwen3, output format matters.

This guide will show you how to:

  • Generate valid JSON for parsing or APIs

  • Create tables for reports and analysis

  • Use markdown formatting for readable outputs

  • Control output precision and consistency

With the right prompts, Qwen3 can act like a reliable backend service—not just a chatbot.


1. Basic Prompt Structure

Use OpenAI-style chat format:

text
<|im_start|>system You are a JSON generator bot. Always return clean JSON. <|im_end|> <|im_start|>user Convert this info into JSON: Name: Alice, Age: 24, Skills: Python, ML <|im_end|> <|im_start|>assistant { "name": "Alice", "age": 24, "skills": ["Python", "ML"] }

✅ Use system to lock the output format style.


2. Generate JSON for APIs & Functions

Prompt Template:

text
<|im_start|>system Respond only in raw JSON. No extra text or explanations. <|im_end|> <|im_start|>user Create a product object with name, price, stock, and tags. <|im_end|>

Qwen3 Output:

json
{ "name": "Smart Watch", "price": 199.99, "stock": 42, "tags": ["electronics", "wearable", "fitness"] }

3. Generate Markdown (Great for Docs, UIs)

Prompt:

text
<|im_start|>system Format your answer in markdown. <|im_end|> <|im_start|>user Write a comparison of Qwen3 and GPT-4. <|im_end|>

Output:

markdown
| Feature | Qwen3 | GPT-4 | |----------------|----------------|----------------| | Open Source | ✅ Yes | ❌ No | | Max Context | 128K tokens | 128K tokens | | Cost | Free (local) | Paid |

4. Generate Tables

Great for BI dashboards, reports, and knowledge summaries.

Prompt:

text
<|im_start|>system Return a markdown table comparing LLMs by model size and benchmark scores. <|im_end|>

Output:

markdown
| Model | Params | HumanEval | MMLU | |---------------|--------|-----------|------| | Qwen3-7B | 7B | 78.4% | 62.1 | | GPT-4-Turbo | ? | 90.2% | 86.0 | | Claude Sonnet | ? | 82.3% | 78.5 |

5. Create Structured Instruction Outputs

To guide downstream tools or logic.

Prompt:

text
<|im_start|>system Return output in this structure: { "task": "", "steps": [], "tools": [] } <|im_end|> <|im_start|>user I want to automate sending emails with Python. <|im_end|>

Output:

json
{ "task": "Send emails with Python", "steps": [ "Install smtplib", "Compose email content", "Connect to SMTP server", "Send the email" ], "tools": ["Python", "smtplib"] }

6. Prompt Engineering Tips

Tip Why It Works
Use system role clearly Sets behavior before all input
Be explicit in format Avoids natural language drift
Add formatting constraints e.g., "Respond in valid JSON"
Limit token length Keeps responses short/structured
Use examples in prompts Boosts pattern matching accuracy

7. Common Use Cases for Structured Prompts

Use Case Format Why It Helps
Chatbot Actions JSON For APIs and routing logic
UI Components Markdown Table, bullets, headers
Tool Invocation JSON / Functions Helps agents reason + call tools
Report Summaries Markdown table Great for auto-generated reports
Data Transformation Structured text CSV, table, XML, YAML-like output

Conclusion: Structure Is Power

Qwen3 is highly capable at returning clean, structured, and parsable output—you just need to give it the right prompt shape.

Use this for:

  • API backends

  • Agent chains

  • AI dashboards

  • Developer tools

With structured prompting, Qwen3 becomes a reliable machine partner, not just a creative writer.


Resources



Qwen3 Coder - Agentic Coding Adventure

Step into a new era of AI-powered development with Qwen3 Coder the world’s most agentic open-source coding model.