Zero-Shot Classification
Classify text into predefined categories without examples. Best for clear-cut categories where the labels are self-explanatory.
System Message
// Zero-Shot Classification system template
// Replace {{placeholders}} with your actual values before sending
You are a text classifier. Categorize the given text into exactly one of the following categories: {{category_1}}, {{category_2}}, {{category_3}}.
Respond with ONLY the category name. No explanation, no punctuation.
Code Fragment I.1.1: Instructs the model to classify text into predefined categories without examples. The strict output constraint ensures machine-parseable responses.
User Message
// Zero-Shot Classification user template
// Replace {{placeholders}} with your actual values before sending
Classify this text:
"""
{{input_text}}
"""
Code Fragment I.1.2: Wraps the input text in triple-quoted delimiters so the model can distinguish the text to classify from the instruction itself.
Tip
For higher accuracy, add a brief description of each category in the system message. For example: "positive (the author expresses satisfaction), negative (the author expresses dissatisfaction), neutral (no clear sentiment)."
Few-Shot Classification
Provide labeled examples so the model learns the classification pattern. Especially useful for nuanced or domain-specific categories.
System Message
// Few-Shot Classification system template
// Replace {{placeholders}} with your actual values before sending
You are a customer support ticket router. Classify each ticket into one of: billing, technical, account, general.
Examples:
Text: "I was charged twice for my subscription this month."
Category: billing
Text: "The app crashes every time I try to upload a photo."
Category: technical
Text: "How do I change the email address on my account?"
Category: account
Code Fragment I.1.3: Provides labeled examples before the query so the model learns the target format and decision boundary from context.
User Message
// Few-Shot Classification user template
// Replace {{placeholders}} with your actual values before sending
Text: "{{input_text}}"
Category:
Code Fragment I.1.4: Passes the new text to classify in the same format as the few-shot examples, maintaining structural consistency.
Tip
Use 3 to 5 examples that cover the boundary cases, not just the obvious ones. Balance examples across categories. Place the most ambiguous examples last, as models pay more attention to recent examples.