August 13, 2026 · 19 min read
Prompt engineering is the difference between mediocre and exceptional AI outputs. Chinese AI models — DeepSeek, GLM-4, Qwen, Kimi — each respond differently to prompting techniques. This guide distills the most effective patterns we've tested across thousands of production queries through TokenEase.
The simplest approach — ask the model directly without examples.
# Effective zero-shot prompt
prompt = """Summarize the following article in 3 bullet points, each under 20 words:
Article:
{article_text}
Format your response as:
- Point 1
- Point 2
- Point 3"""
# Ineffective zero-shot prompt
bad_prompt = "Summarize this." # Too vague
Provide examples to guide the model's output style and format.
few_shot_prompt = """Extract named entities from text. Return as JSON.
Example 1:
Text: "Apple Inc. announced a partnership with TSMC in Cupertino."
Output: {
"organizations": ["Apple Inc.", "TSMC"],
"locations": ["Cupertino"],
"people": []
}
Example 2:
Text: "Elon Musk visited Beijing to meet with CATL executives."
Output: {
"organizations": ["CATL"],
"locations": ["Beijing"],
"people": ["Elon Musk"]
}
Now extract from:
Text: "{input_text}"
Output:"""
response = requests.post(
f"{BASE_URL}/chat/completions",
headers={"Authorization": f"Bearer {TOKEN}"},
json={
"model": "deepseek-v4",
"messages": [{"role": "user", "content": few_shot_prompt}],
"temperature": 0.1 # Low temp for consistent formatting
}
)
Ask the model to think step-by-step before answering. Critical for reasoning tasks.
cot_prompt = """Solve the following math problem step by step.
Show your reasoning, then provide the final answer.
Problem: A store has a 20% off sale. An item originally costs $80.
After the discount, there's an additional 10% off with a coupon.
What is the final price?
Step 1:"""
# For models that support reasoning (DeepSeek-V4, GLM-4)
response = requests.post(
f"{BASE_URL}/chat/completions",
json={
"model": "deepseek-v4",
"messages": [{"role": "user", "content": cot_prompt}],
"temperature": 0.3
}
)
auto_cot_prompt = """You are an expert problem solver. For the question below:
1. First, generate 3 similar but simpler example problems and solve them
2. Then solve the actual problem using the same approach
Question: {complex_question}
Let's work through this:"""
# Auto-CoT often outperforms manual few-shot on novel problem types
Assign a specific role to improve output quality and relevance.
roles = {
"technical_writer": "You are a senior technical writer with 10 years of experience. Write clear, concise documentation.",
"code_reviewer": "You are a principal engineer at a top tech company. Review code for correctness, performance, and security.",
"data_analyst": "You are a data scientist specializing in business analytics. Interpret data and provide actionable insights.",
"legal_advisor": "You are a corporate lawyer. Provide legal analysis with appropriate caveats.",
"translator": "You are a professional translator fluent in Chinese and English. Preserve tone, nuance, and technical accuracy."
}
# Example usage
prompt = f"""{roles['code_reviewer']}
Review the following Python function for potential issues:
```python
def process_user_data(data):
query = f"SELECT * FROM users WHERE id = {data['user_id']}"
return db.execute(query)
```
Identify:
1. Security issues
2. Performance concerns
3. Code style improvements"""
| Role | Use Case | Quality Improvement |
|---|---|---|
| Technical Writer | Documentation | +25% clarity |
| Senior Engineer | Code review | +40% issue detection |
| Data Scientist | Analysis | +30% insight depth |
| Legal Advisor | Contract review | +20% accuracy |
Force the model to return valid JSON for programmatic use.
json_prompt = """Analyze the following customer review and return ONLY a JSON object.
Do not include any text before or after the JSON.
Review: "The product is amazing! Shipping was fast but the packaging was damaged. Customer service was helpful."
Return this exact structure:
{
"sentiment": "positive|neutral|negative",
"sentiment_score": 0.0 to 1.0,
"aspects": [
{
"aspect": "aspect name",
"sentiment": "positive|neutral|negative",
"quote": "relevant quote from review"
}
],
"key_phrases": ["phrase 1", "phrase 2"]
}"""
response = requests.post(
f"{BASE_URL}/chat/completions",
json={
"model": "glm-4",
"messages": [{"role": "user", "content": json_prompt}],
"temperature": 0.1,
"response_format": {"type": "json_object"} # Force JSON output
}
)
Generate multiple answers and take the majority vote for higher accuracy.
def self_consistent_answer(question, n_samples=5):
"""Generate multiple answers and return the most common one"""
answers = []
for _ in range(n_samples):
response = requests.post(
f"{BASE_URL}/chat/completions",
json={
"model": "deepseek-v4",
"messages": [
{"role": "system", "content": "Answer the question concisely."},
{"role": "user", "content": question}
],
"temperature": 0.7 # Higher temp for diversity
}
)
answer = response.json()["choices"][0]["message"]["content"]
answers.append(answer.strip().lower())
# Return most common answer
from collections import Counter
most_common = Counter(answers).most_common(1)[0][0]
return most_common
# Use case: Fact-checking, math problems, classification
# Cost: 5× normal, but accuracy improvement often worth it
Break complex tasks into sequential prompts, using each output as the next input.
def prompt_chain(document):
"""Multi-step document analysis pipeline"""
# Step 1: Extract key facts
step1 = f"""Extract the 5 most important facts from this document:
{document}
Return as a numbered list."""
facts = call_llm(step1)
# Step 2: Analyze sentiment
step2 = f"""Based on these facts, what is the overall sentiment?
Facts: {facts}
Return: positive, neutral, or negative."""
sentiment = call_llm(step2)
# Step 3: Generate summary
step3 = f"""Write a 2-sentence summary of this document.
Key facts: {facts}
Sentiment: {sentiment}
Summary:"""
summary = call_llm(step3)
return {"facts": facts, "sentiment": sentiment, "summary": summary}
response_format| Mistake | Why It Fails | Fix |
|---|---|---|
| "Be creative" without constraints | Output is too random | Add style guidelines and examples |
| Overloading context | Model loses track of instructions | Use prompt chaining instead |
| Inconsistent formatting | Hard to parse programmatically | Use JSON mode with schema |
| Assuming domain knowledge | Model hallucinates facts | Provide context or use RAG |
| Ignoring temperature | Too random or too rigid | 0.1 for structured, 0.7 for creative |
prompt_configs = {
"structured_extraction": {
"temperature": 0.1,
"top_p": 0.1,
"description": "Low randomness for consistent formatting"
},
"factual_qa": {
"temperature": 0.3,
"top_p": 0.5,
"description": "Slightly higher for natural language"
},
"code_generation": {
"temperature": 0.2,
"top_p": 0.3,
"description": "Low randomness, deterministic code"
},
"creative_writing": {
"temperature": 0.8,
"top_p": 0.9,
"description": "High randomness for creativity"
},
"brainstorming": {
"temperature": 1.0,
"top_p": 1.0,
"description": "Maximum diversity for ideas"
}
}
def evaluate_prompt(prompt_template, test_cases, model="deepseek-v4"):
"""Systematic prompt evaluation"""
results = []
for test in test_cases:
prompt = prompt_template.format(**test["inputs"])
response = requests.post(
f"{BASE_URL}/chat/completions",
json={
"model": model,
"messages": [{"role": "user", "content": prompt}],
"temperature": 0.3
}
)
output = response.json()["choices"][0]["message"]["content"]
# Check formatting
format_correct = validate_format(output, test["expected_format"])
# Check content (using another LLM call or heuristic)
content_score = score_relevance(output, test["expected_content"])
results.append({
"input": test["inputs"],
"output": output,
"format_correct": format_correct,
"content_score": content_score
})
avg_score = sum(r["content_score"] for r in results) / len(results)
format_accuracy = sum(r["format_correct"] for r in results) / len(results)
return {
"avg_content_score": avg_score,
"format_accuracy": format_accuracy,
"details": results
}
Apply these techniques with TokenEase:
For advanced patterns, see our guides on RAG implementation and AI agent development.
Last updated: August 2026. Optimal prompts vary by model version and use case.