Text classification is one of the most common NLP tasks—from sentiment analysis to content moderation. While LLMs are primarily designed to generate text, we can leverage them for classification by carefully structuring our prompts. In this lesson, you’ll learn proven patterns to get reliable, consistent classifications.
Provide examples to establish the pattern and decision boundaries.
Copy
Ask AI
Classify customer feedback into categories.Example 1: "Fast shipping, great quality" → Category: Product QualityExample 2: "Customer service was unhelpful" → Category: Customer ServiceExample 3: "Website is hard to navigate" → Category: User ExperienceNow classify: "The checkout process was confusing"Category:
Get both the classification and the reasoning behind it.
Copy
Ask AI
Classify the following email as Spam or Not Spam.Provide your reasoning, then give the final classification.Email: "Congratulations! You've won $1,000,000! Click here to claim your prize now!"Reasoning:Classification:
Output:
Copy
Ask AI
Reasoning: This email contains typical spam indicators: unrealistic prize claim, urgency tactics, and suspicious links without context.Classification: Spam
When items can belong to multiple categories simultaneously.
Copy
Ask AI
Classify the following article into one or more categories: Technology, Business, Health, Politics, Entertainment.Article: "Apple announces new health features in latest iPhone, boosting stock prices."Categories (comma-separated):
First, classify the broad category, then the specific subcategory.Text: "The laptop's battery life is disappointing."Step 1 - Broad Category (Product, Service, Shipping, Other):Step 2 - Specific Issue (if Product: Quality, Performance, Design, Price):
Provide clear definitions when examples aren’t available.
Copy
Ask AI
Classify the following text using these definitions:- Informative: Provides factual information or explanations- Persuasive: Attempts to convince or influence opinion- Entertaining: Primarily for amusement or enjoyment- Instructional: Teaches how to do somethingText: "Follow these steps to bake the perfect chocolate cake."Classification:
Classify the sentiment. If ambiguous, explain why and provide the most likely classification.Text: "The service was fast, but the food was cold."Analysis:Classification:
Output:
Copy
Ask AI
Analysis: Mixed sentiment - positive about speed, negative about quality. The negative aspect (core product) likely outweighs the positive (service speed).Classification: Negative
Classify into: Bug Report, Feature Request, Question, or Other.If "Other", briefly explain.Text: "I love the new design!"Classification:Explanation (if Other):
Output:
Copy
Ask AI
Classification: OtherExplanation: This is positive feedback/praise, not fitting the technical support categories.
Create a prompt to classify movie reviews as Positive, Negative, or Mixed. Test with:
“Best film I’ve seen this year!”
“Terrible acting, waste of time”
“Great visuals but weak plot”
Sample Solution
Copy
Ask AI
Classify the movie review sentiment as exactly one of: Positive, Negative, or Mixed.Positive: Overall recommendation, more positive than negative aspectsNegative: Overall not recommended, more negative than positive aspects Mixed: Balanced positive and negative aspectsReview: [INSERT REVIEW]Sentiment:
Design a prompt to classify social media posts as Safe, Review, or Unsafe based on content policy.
Sample Solution
Copy
Ask AI
Classify social media content according to these categories:Safe: Appropriate for all audiences, no policy violationsReview: Potentially problematic, needs human review (borderline cases)Unsafe: Clear policy violation (hate speech, violence, explicit content)Post: [INSERT POST]Classification:Reason:
Create a prompt to tag news articles with relevant topics (can have multiple tags).
Sample Solution
Copy
Ask AI
Tag the following news article with all relevant categories from this list:Politics, Technology, Business, Health, Science, Sports, Entertainment, EnvironmentProvide tags as a comma-separated list.Article: [INSERT ARTICLE]Tags:
Let’s build a complete email classification system:
Copy
Ask AI
You are an email triage assistant. Classify emails into categories and assign priority.Categories:- Sales: Customer inquiries about products/services- Support: Technical issues or help requests - Billing: Payment, invoices, refunds- Feedback: Suggestions, complaints, reviews- Spam: Unsolicited or irrelevant messagesPriority Levels:- High: Urgent issues, angry customers, time-sensitive- Medium: Standard requests, general inquiries- Low: Feedback, non-urgent questionsEmail: "I was charged twice for my subscription this month. Please refund the duplicate charge immediately."Category:Priority:Reasoning: