6.1.1. Classification, Sentiment, and Entity Extraction via Generative Models
💡 First Principle: Going LLM-first means constraining the model so its output is reliable — an enum of allowed labels, a JSON schema, low temperature. The model is flexible by default; text analysis needs it to be disciplined, and you enforce that with structured output, not hope.
For classification, you provide the categories (ideally as an enum in a JSON schema) and the model assigns one — but without constraints it may invent labels. For sentiment, you prompt for a fixed scale and structured result. For entity/key-phrase extraction, you prompt the model to pull entities into typed fields. The Phase 2 tools apply directly: structured output guarantees parseable shape, low temperature gives repeatability, and few-shot examples steer edge cases. The payoff is one model handling several analysis tasks; the discipline is constraining each one.
⚠️ Exam Trap: "Just ask the model to classify into our categories" without constraining the output space is the trap — the model may return a label outside your allowed set. The requirement-correct LLM-first answer uses structured output with an enum/schema (and validation) to bound the categories, not a free-text instruction alone. Schema-valid still isn't fact-valid (Phase 2), so validate.
Reflection Question: You ask a model to tag tickets as Billing/Technical/Account, but it occasionally returns "Other" or "Sales." What did the prompt design omit, and which Phase 2 mechanism fixes it?