STAYCHARTED BLOG · Snowflake and Databricks · Text classification
Classifying text in Snowflake and Databricks: getting the most from AI_CLASSIFY and ai_classify, and when to add a trained model
How to get the most from Snowflake AI_CLASSIFY and Databricks ai_classify, when to add a model trained on your own data, and what we measured on 5,000 rows.
Getting good results from AI_CLASSIFY and ai_classify
Snowflake AI_CLASSIFY
Show SQL example
SELECT ticket_id,
AI_CLASSIFY(
body,
[{'label': 'Billing', 'description': 'charges, refunds, invoices'},
{'label': 'Login', 'description': 'passwords, two-factor, locked accounts'},
{'label': 'Bug'}],
{'task_description': 'Classify a customer support ticket by what the customer needs.',
'examples': [{'input': 'I was charged twice this month',
'labels': ['Billing'],
'explanation': 'a duplicate charge'}]}
):labels[0]::STRING AS category
FROM support_tickets;
- Describe each category in a few words (up to 25 words each), and add a one-line task description. Both help.
- Add a real example per category from rows your team already categorized. In our test, examples lifted accuracy from 82.6% to 84.2% on 21 categories.
- Keep the list short where you can. Snowflake's documentation notes that more than about twenty categories may reduce accuracy. Group categories first, then classify within a group.
- Watch for blanks. A call that fails returns NULL rather than stopping the query.
- Mind the cost. Category names, descriptions and examples are sent with every row, and
billed as tokens on every row. Count tokens on a sample first with
AI_COUNT_TOKENS. - On a trial account, AI functions are off until a payment method is added.
Databricks ai_classify
Show SQL example
SELECT ticket_id,
r:response[0].value::STRING AS category,
r:response[0].confidence_score::DOUBLE AS confidence
FROM (
SELECT ticket_id,
ai_classify(
body,
'{"Billing": "charges, refunds, invoices", "Login": "passwords, two-factor, locked accounts", "Bug": ""}',
MAP('version', '2.1', 'enableConfidenceScores', 'true',
'instructions', 'Classify a customer support ticket by what the customer needs.')
) AS r
FROM support_tickets
);
- Pin version 2.1 and turn on confidence scores: they're what let you send only the unsure rows to a person.
- Use label descriptions and the instructions option for context, as with Snowflake.
- Up to 500 labels are allowed; for very large taxonomies, Databricks suggests narrowing the candidates first.
- Check compute and regional support. It is not available on SQL Classic. On Databricks Runtime, the documented minimum is 15.4 LTS; check current regional requirements.
These examples use a support_tickets table with ticket_id and body. Check them on a small sample in your own account before a full run. Inspect NULL/error results as well as successful classifications; a confidence score is not a guarantee of correctness.
Measure before you rely on it
Whichever function you use, test it the same way before it drives a report or a workflow:
- Take a few thousand rows your team has already categorized, ideally the most recent.
- Run the function on them without the answers, exactly as you will in production.
- Compare overall and per category. A good overall figure can hide categories that are almost always wrong.
- If you have confidence scores, check the share of rows above each cutoff and how many of those are right. That tells you how much can go straight through.
Keep test rows separate from the examples used in prompts or training. Count failed or blank answers in the results, and inspect frequent confusions.
What we measured on 5,000 complaints
We tested public NHTSA vehicle complaints at two levels: 21 vehicle systems and 72 offered subsystem labels, with 70 subsystems represented in the test. Each level contains 5,000 complaints received from January 2025 onward. StayCharted trained on 19,902 older system examples and 19,281 older subsystem examples. All answers were compared with NHTSA’s filing; blanks count as wrong.
| StayChartedAI Model Trainer · model comparison | ||
|---|---|---|
| Approach on the same 5,000 test complaints per level | Vehicle system · 21 labels | Subsystem · 72 offered, 70 in test |
| Most-common-category baseline | 24.6% | 31.8% |
| Snowflake AI_CLASSIFY · system labels only; subsystem labels + task description | 82.6% (4,132 correct) | 52.7% (2,636 correct) |
| Snowflake AI_CLASSIFY · task description + one example per label | 84.2% (4,212 correct) | Not run |
| StayCharted AI Classifier Model | 84.1% | 76.9% |
| Dedicated AI Model | 87.7% | 85.9% (4,296 correct) |
Databricks scores are not available yet, so this table does not rank Databricks against either platform. Its SQL example above explains the documented function, not a measured result.
What we took from it:
- On 21 broad categories, Snowflake did well. Adding a task description and examples raised the score from 82.6% to 84.2%, close to the StayCharted AI Classifier Model’s 84.1%. The Dedicated model scored 87.7%—3.5 percentage points higher using the displayed rounded figures.
- On closely related subsystems, the measured gap was larger. Snowflake scored 52.7% with labels and a task description; the Dedicated model scored 85.9%, or 1,660 more correct answers out of 5,000. This comparison did not test Snowflake with subsystem examples. It cannot establish how every prompt or model configuration would perform.
- Confidence adds a review decision. At a 0.90 cutoff, the Dedicated model covered 71.5% of subsystem complaints with 94.3% accuracy within that share. The remaining 28.5% would need review. Human-review outcomes were not measured. Snowflake AI_CLASSIFY returns labels without a confidence score; Databricks 2.1 supports confidence scores, but we have not measured its coverage here.
The Snowflake runs were scored on 30 October 2026. Blank answers numbered 52 for the system labels-only run, 41 for the system run with examples, and 14 for the subsystem run. The Dedicated subsystem result is the v1.0.65 rerun with no blank answers. Examples for Snowflake came from the training data, not the test rows. Category lists and examples are different from training on all earlier complaints; this is a comparison of the tested workflows.
Data preparation, time split and full trained-model results →
When to add a trained model
Keep the built-in function when the categories are few, broad and say what they mean, and when an occasional wrong answer is cheap.
Consider a model trained on your own decisions when:
- You have many categories, or close ones: dozens of product types, failure codes, account and department combinations, ticket queues.
- The categories are your company's own, with rules nobody wrote down, so names and descriptions can't carry them.
- You need to automate part of the work, which takes a confidence you can trust and a queue for the rest.
- You already have history: a few hundred to a few thousand rows your team has categorized.
The two work together. You can keep the built-in function for broad, low-stakes tagging and use a trained model for the classifications that drive money, compliance or customer outcomes.
Using a trained model from your warehouse
StayCharted AI Model Trainer learns from rows your team already categorized. It returns a category, confidence and review flag for new rows. On Essentials and Business, answers below the model’s cutoff go to the Review Queue. Reviewers’ corrections can train the next version; retrain and publish before expecting them to change future answers.
- Export, fill, load back: export CSV rows, train and fill in StayCharted, then load the reviewed results into a warehouse table. Preserve a stable row key so your SQL can join the results back.
- Call the Prediction API: your integration can call a published model from warehouse-connected code with approved external network access. Store credentials securely and handle rate limits, failures and retries in the integration. See the API reference.
Your source tables can remain in the warehouse, but the rows sent for training or classification are processed by StayCharted. This is not computation entirely inside your warehouse. Check your data-handling requirements before sending them.
Common questions
How do I classify text in Snowflake?
Use AI_CLASSIFY with your category names, a short description of each, a task description and an example per category. Test it on rows your team has already categorized before relying on it.
How do I get a confidence score from ai_classify in Databricks?
Use version 2.1 and set enableConfidenceScores to true in the options map. Each label in the response then has a score from 0 to 1.
Does Snowflake AI_CLASSIFY return a confidence score?
No. It returns the labels.
How many categories can AI_CLASSIFY handle?
Snowflake's documentation notes that more than about twenty categories may reduce accuracy. In our test, accuracy was 82.6% with 21 categories and 52.7% with 72. These are different classification tasks, so the category count alone does not explain the difference.
How accurate is AI_CLASSIFY?
On these 5,000 NHTSA test complaints per level, Snowflake scored 82.6% with 21 system labels and 84.2% with a task description and examples. With 72 subsystem labels plus a task description, it scored 52.7%. That subsystem run did not include examples. Your own data and configuration will differ.
When is a trained model worth it?
When you have many or closely related categories, categories specific to your company, and a history of rows your team has already categorized. In our test, a trained model was 3.5 points ahead on 21 categories and 33.2 points ahead on 72.
Can I use a trained model without moving my data?
Your warehouse can remain the system of record. Export selected rows and load answers back, or call the Prediction API through your own integration. The rows sent for training and classification are processed by StayCharted; they do not stay entirely inside the warehouse.