text-classification
Published
Public
in @structured-extraction

Classify text into a caller-supplied label set (you define the labels at call time). Returns the single best-fit label with a rationale and confidence. Optional fallback label.

text-classification

Assign a piece of text to exactly one label from a caller-supplied label set. You define the labels and their definitions at call time; the prompt returns the single best fit with a rationale and confidence.

Use it for ticket categorization, intent tagging, content routing, topic labeling — anywhere the taxonomy is yours, not baked into the prompt.

Entrypoints

EntrypointRendersInputs
systemInstructions + your label definitions + embedded output schemalabels, optional fallbackLabel
userThe delimited text block to classifytext

Variables

  • labels (array, required) — your candidate labels. Each item is { name, description }:
    • name (string) — machine-readable identifier, e.g. billing_issue.
    • description (string) — one-sentence definition of when the label applies. Good descriptions drive accuracy far more than the model choice does.
  • fallbackLabel (string, optional) — emitted when nothing fits, e.g. other. Omit it to force the model to always pick the closest label.
  • text (string, required) — the text to classify.

Output

{
  "rationale": "Mentions a duplicate charge on the monthly invoice.",
  "label": "billing_issue",
  "confidence": 0.91
}
  • rationale is emitted before label (reasoning-first; the system prompt pins the order).
  • confidence is self-reported and ⚠️ not calibrated — a rough triage signal, not a probability.

⚠️ The label cannot be schema-validated

Because the label set is runtime input but the output schema is fixed per version, the generated parseOutput() can guarantee label is a string but cannot verify it's one of the labels you passed. Add a one-line membership check in your code:

const out = parseOutput(raw);
if (!labels.some(l => l.name === out.label)) {
  // handle off-taxonomy label (retry, route to fallback, log)
}

House conventions

  • Triple-mustache for text, label name/description, and fallbackLabel so special characters in your taxonomy are never HTML-escaped.
  • Exactly one label, matched character-for-character against your set.
  • Empty / garbage input → closest label (or fallback) with low confidence.
  • Strict schemaadditionalProperties: false, confidence bounded 0–1.

Notes

Verified by local render with a sample label set. Suggested default model claude-sonnet-4-6 at temperature: 0.

@sufleur/