Classification
Use the Vault SDK to classify text into predefined categories. Covers single-label, multi-label, and schema-validated classification.
Single-label
Classify input into exactly one category. Constrain the model to return only the label name.
lib/classify.ts
import { vault } from '@/lib/vault';
const LABELS = ['billing', 'technical', 'feature-request', 'other'] as const;
type Label = typeof LABELS[number];
export async function classifySupportTicket(text: string): Promise<Label> {
const result = await vault.infer({
model: 'vault-3-turbo',
prompt: `Classify this support ticket into exactly one of these categories:
${LABELS.join(', ')}
Respond with only the category name, nothing else.
Ticket: ${text}`,
maxTokens: 20,
});
const label = result.text.trim().toLowerCase() as Label;
return LABELS.includes(label) ? label : 'other';
}Multi-label
Allow multiple categories per input. Ask the model to return a comma-separated list.
lib/classify-multi.ts
export async function classifyMulti(text: string): Promise<Label[]> {
const result = await vault.infer({
model: 'vault-3-turbo',
prompt: `Apply all relevant labels from this list: ${LABELS.join(', ')}
Return a comma-separated list of matching labels only. No explanations.
Text: ${text}`,
maxTokens: 40,
});
return result.text
.split(',')
.map((l) => l.trim().toLowerCase() as Label)
.filter((l) => LABELS.includes(l));
}With Schema
Return a structured result with the label plus a confidence score and reasoning.
lib/classify-schema.ts
import { z } from 'zod';
const ClassificationSchema = z.object({
label: z.enum(LABELS),
confidence: z.number().min(0).max(1),
reasoning: z.string().max(100),
});
export async function classifyWithReasoning(text: string) {
const result = await vault.infer({
model: 'vault-3-pro',
prompt: `Classify this text and return JSON:
{ "label": one of ${LABELS.join('|')}, "confidence": 0-1, "reasoning": string }
Text: ${text}`,
maxTokens: 150,
});
return ClassificationSchema.parse(JSON.parse(result.text));
}