classify-message
This example classifies a message three ways: a string-literal union for its category, a string enum for sentiment, and an inline union for urgency.
Nola derives a JSON Schema enum from each type. The runtime checks the answer against the allowed values and includes them in a correction retry if the model returns an invalid label. Providers that support structured output also receive the schema.
The string enum is available at runtime, so callers can compare a result with Sentiment.Negative. The urgency answer is converted to a boolean in the return value. Nola does not yet support a separate description for each label.
export type Category = "billing" | "refund" | "fraud" | "other";
export enum Sentiment { Positive = "positive", Neutral = "neutral", Negative = "negative",}
export infer function classifyMessage(.message: string) { const category = ask `the category of the customer message`: Category; const sentiment = ask `the overall sentiment of the message`: Sentiment; const urgent = ask `does the message need urgent attention`: "yes" | "no"; return { category, sentiment, urgent: urgent === "yes" };}Run it
Section titled “Run it”npx nola-lang run src/main.ts # mock provider (deterministic)# real model: edit nola.config.ts to openai({ model: "gpt-5-mini" }) (needs OPENAI_API_KEY)Scaffold: npm create nola my-app -- --template classify-message
Source: examples/classify-message on GitHub. The full walkthrough is Classification.
Next: Introduction — back to the start.