logo
P
Prompt Master

Prompt 大师

掌握和 AI 对话的艺术

Classification Prompts

Basic classification prompts and quick-start guide

This chapter covers common Classification Prompt templates for testing and deploying LLM text classification. Classification is one of the most fundamental and practical NLP tasks -- nail it and you can build all kinds of automation pipelines fast.


What Is Text Classification?

Text Classification assigns a piece of text to one or more predefined categories.

┌─────────────────────────────────────────────────────────────┐
│                    Classification Flow                        │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│   Input Text          →      LLM Analysis   →   Output Label│
│                                                             │
│  "This product is great!"   Understand semantics  positive  │
│  "Terrible service"         Judge sentiment       negative  │
│  "It's okay"                Match label           neutral   │
│                                                             │
└─────────────────────────────────────────────────────────────┘

Why Classification Matters

Use CaseSpecific ApplicationBusiness Value
Customer ServiceTicket routing, mood detection, priorityFaster response
Content ModerationSpam, policy violations, sensitive topicsLower manual costs
Email ProcessingSpam filtering, email type classificationBetter productivity
User FeedbackReview sentiment, NPS predictionUser insight
Smart RoutingIssue type detection, department dispatchOptimized workflows

Common Classification Types

TypeLabel ExamplesTypical Scenario
Sentiment Analysispositive / negative / neutralReview analysis, monitoring
Intent Detectioninquiry / complaint / refund / buyChatbots
Topic Classificationtech / finance / sports / entertainmentNews categorization
Urgency Levelhigh / medium / lowTicket systems
Language DetectionChinese / English / JapaneseMulti-language routing
Spam Detectionspam / not_spamEmail filtering

Core Prompt Structure

A good Classification Prompt needs these elements:

┌─────────────────────────────────────────────────────────────┐
│               Classification Prompt Structure                │
├─────────────────────────────────────────────────────────────┤
│                                                             │
│  1. Task description  - Clearly state what to do            │
│  2. Label space       - List all possible categories        │
│  3. Output constraint - Specify format (label only / JSON)  │
│  4. Input data        - The text to classify                │
│                                                             │
└─────────────────────────────────────────────────────────────┘

General Template

Classify the following text into the specified categories.

Categories: {label_1} / {label_2} / {label_3}

Requirements:
- Output only the category name, no explanation
- If uncertain, output "unknown"

Text: {input_text}

Category:

Quick Start: Zero-shot Classification

The simplest approach -- just tell the LLM which labels to use:

Prompt:

Classify the text into neutral, negative, or positive.

Text: I think the food was okay.

Sentiment:

Output:

neutral

This works for:

  • Quick prototyping
  • Clear-cut label semantics
  • Tasks where consistency isn't critical

Few-shot Classification: More Stable Output

When you need more stable, predictable output formatting, use Few-shot (provide 2-5 examples):

Prompt:

Classify the text as positive / negative / neutral.

Examples:
Text: This product is amazing, highly recommend!
Classification: positive

Text: Terrible service, never coming back.
Classification: negative

Text: It's alright, nothing special.
Classification: neutral

Now classify:
Text: Beautiful packaging, but the taste is average.
Classification:

Output:

neutral

Example 1: Sentiment Analysis

The most common classification task -- detecting emotional tone in text.

Scenario: E-commerce review analysis

Prompt:

You are a sentiment analysis expert. Analyze the sentiment of the following product review.

Classification criteria:
- positive: Positive evaluation, satisfaction, recommendation
- negative: Negative evaluation, dissatisfaction, complaint
- neutral: Neutral evaluation, stating facts, no clear sentiment

Review: Shipping was fast, but the packaging was slightly damaged. Overall acceptable.

Sentiment:

Output:

neutral

Example 2: Intent Classification

Identify user message intent -- commonly used in customer service bots.

Scenario: Smart customer service

Prompt:

You are a customer service intent classifier. Identify the intent of the user message.

Intent types:
- inquiry: Asking about product info, usage instructions
- complaint: Expressing dissatisfaction, requesting resolution
- refund: Requesting refund or return
- other: Messages that don't fit other categories

User message: The phone I bought last week has a cracked screen. It's only been three days -- how are you going to handle this?

Intent:

Output:

complaint

Example 3: Topic Classification

Categorize text into different subject areas.

Scenario: News content classification

Prompt:

Classify the following news headline into the appropriate topic.

Topic options:
- Technology: Internet, AI, phones, software
- Finance: Stock market, economy, investment, business
- Sports: Events, athletes, match results
- Entertainment: Celebrities, film/TV, variety shows, music
- Society: Public interest, events, policy

Headline: Apple launches iPhone 16 with the new A18 chip

Topic:

Output:

Technology

Example 4: Urgency Classification

Determine ticket or request priority.

Scenario: Ticket system

Prompt:

You are a ticket priority classifier. Judge the urgency based on ticket content.

Urgency criteria:
- High: System outage, data loss, security vulnerability, affecting many users
- Medium: Feature malfunction, performance issues, affecting some users
- Low: UI issues, feature requests, general inquiries

Ticket: Users report the login page loads very slowly, taking over 10 seconds, affecting about 20% of users.

Urgency:

Output:

Medium

Example 5: Multi-label Classification

Sometimes a single text belongs to multiple categories.

Scenario: Content tagging

Prompt:

You are a content tag classifier. Add appropriate tags to the following article.

Available tags:
- Artificial Intelligence
- Software Development
- Career Growth
- Learning Methods
- Tool Recommendations

Requirements:
- Select 1-3 most relevant tags
- Output format: tag1, tag2

Article summary: This article covers how to use ChatGPT to boost programming productivity, including code generation, bug fixing, and code review -- helping developers stay competitive in the AI era.

Tags:

Output:

Artificial Intelligence, Software Development, Tool Recommendations

Advanced Tips: Improving Classification Accuracy

1. Define Boundary Conditions

Classification criteria:
- positive: Must have clearly positive words or recommendation intent
- negative: Must have clearly negative words or complaint intent
- neutral: No clear sentiment, or mixed positive/negative

Edge cases:
- "it's fine" "average" "okay" → neutral
- "great but a bit expensive" → judge by overall leaning

2. Add Confidence Scores

Classify and provide a confidence score (0-100).

Output format:
Classification: {label}
Confidence: {score}

If confidence is below 70, explain why.

3. Use JSON Structured Output

Output classification results in JSON format:

{
  "text": "original text",
  "category": "classification",
  "confidence": 0.95,
  "reasoning": "brief rationale"
}

Common Problems & Solutions

ProblemCauseSolution
Unstable output formatPrompt constraints too vagueExplicitly say "output label only"
Inconsistent casingNo example constraintsProvide few-shot examples
Wrong edge casesVague label definitionsAdd detailed criteria
Output includes explanationDidn't forbid itAdd "do not explain"
Refuses to classifyModel is uncertainAdd "unknown" fallback option

Zero-shot vs Few-shot Comparison

DimensionZero-shotFew-shot
Prompt lengthShortLong
Output stabilityLowerHigher
Format consistencyMay varyHigh
Best forQuick prototyping, simple tasksProduction, high-precision needs
Token costLowHigh

Recommendation:

  • Use Zero-shot during development for quick validation
  • Use Few-shot in production for stability

API Examples

Python (OpenAI)

from openai import OpenAI

client = OpenAI()

def classify_sentiment(text: str) -> str:
    response = client.chat.completions.create(
        model="gpt-4o",
        messages=[
            {
                "role": "system",
                "content": "You are a sentiment classifier. Output only one of: positive/negative/neutral."
            },
            {
                "role": "user",
                "content": f"Classify the sentiment of the following text:\n\n{text}"
            }
        ],
        temperature=0,  # Set to 0 for consistency
        max_tokens=10
    )
    return response.choices[0].message.content.strip()

# Usage
result = classify_sentiment("This product is amazing!")
print(result)  # positive

Python (Claude)

import anthropic

client = anthropic.Anthropic()

def classify_intent(text: str) -> str:
    message = client.messages.create(
        model="claude-sonnet-4-20250514",
        max_tokens=50,
        messages=[
            {
                "role": "user",
                "content": f"""Identify the intent of the following user message.

Intent types: inquiry / complaint / refund / other

Output only the intent type, no explanation.

User message: {text}

Intent:"""
            }
        ]
    )
    return message.content[0].text.strip()

# Usage
result = classify_intent("I want to return the shirt I bought last week")
print(result)  # refund

Hands-on Exercises

Open ChatGPT or Claude and try these:

Exercise 1: Basic Sentiment Classification

Classify the following reviews as positive / negative / neutral:

1. Super fast shipping, arrived the next day
2. Terrible quality, broke after one week
3. Price is fair, about the same as market rate
4. Customer service was great, patiently answered all my questions
5. Neither good nor bad, just average

Output format:
1. [label]
2. [label]
...

Exercise 2: Design Your Own Classifier

Try designing a Classification Prompt for these scenarios:

  • Email classification (work / personal / promotional / spam)
  • Bug report classification (UI / functionality / performance / security)
  • Social post sentiment (happy / sad / angry / neutral)

Dive deeper into Classification techniques:


Takeaways

Classification is one of the most practical prompt skills. Remember these:

  1. Define the label space: Clearly list all possible categories
  2. Constrain the output format: Specify "output label only" to avoid extra noise
  3. Use Few-shot: In production, use examples for stability
  4. Handle edge cases: Add "unknown" or define clear classification criteria
  5. Low temperature: Set temperature=0 in API calls for consistency

Master Classification and you can build all kinds of automated classification pipelines fast.