DEV Community

shashank ms
shashank ms

Posted on

Text Classification with LLM Models: A Comprehensive Overview

We are going to build a support ticket classifier that reads incoming customer messages and returns a structured category and urgency label. This removes manual triage for support teams and routes issues to the right queue automatically. I will walk through the complete script, from client setup to batch inference, using Oxlo.ai's OpenAI-compatible API.

What you'll need

You need Python 3.10 or newer, the OpenAI SDK (pip install openai), and an Oxlo.ai API key from https://portal.oxlo.ai. Because Oxlo.ai uses request-based pricing, your cost per classification stays the same even when ticket text gets long, which makes this workload especially predictable.

Step 1: Configure the Oxlo.ai client

I start by importing openai and pointing the client at Oxlo.ai. The base URL and key are the only differences from the standard OpenAI setup.

from openai import OpenAI

client = OpenAI(base_url="https://api.oxlo.ai/v1", api_key="YOUR_OXLO_API_KEY")

Step 2: Define the classification schema and system prompt

I constrain the model to return strict JSON with two keys, category and urgency, so I can parse the result without regex hacks. Keeping the prompt explicit and short reduces token overhead and keeps latency low.

SYSTEM_PROMPT = """You are a support ticket classifier.
Analyze the user's message and return a JSON object with exactly two keys: "category" and "urgency".
Valid categories are: Billing, Technical, Account, General.
Valid urgency levels are: Low, Medium, High.
Return only the JSON object. Do not wrap it in markdown or add explanation."""

Step 3: Build the classifier function

I wrap the API call in a small function that sends the ticket text to llama-3.3-70b, strips any accidental markdown fences, and returns a Python dict. I set temperature low because classification is a task where you want deterministic output.

import json

def classify_ticket(user_message: str) -> dict:
    response = client.chat.completions.create(
        model="llama-3.3-70b",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": user_message},
        ],
        temperature=0.1,
        max_tokens=128,
    )

    raw = response.choices[0].message.content.strip()
    if raw.startswith("

```"):
        raw = raw.split("\n", 1)[1].rsplit("```

", 1)[0].strip()
    return json.loads(raw)

Step 4: Classify a batch of tickets

Now I run a list of real-looking tickets through the function and collect the results. This loop is the core of the pipeline; you can swap the list for a database cursor or message queue reader in production.

tickets = [
    "I was charged twice for my subscription this month.",
    "How do I reset my password?",
    "The API returns a 500 error every time I post to /v1/inference.",
    "Can I change my profile picture?",
]

for ticket in tickets:
    label = classify_ticket(ticket)
    print(json.dumps({"ticket": ticket, "label": label}))

Run it

Save the script as classify.py, export your API key, and run python classify.py. You should see structured output similar to this:

{"ticket": "I was charged twice for my subscription this month.", "label": {"category": "Billing", "urgency": "High"}}
{"ticket": "How do I reset my password?", "label": {"category": "Account", "urgency": "Low"}}
{"ticket": "The API returns a 500 error every time I post to /v1/inference.", "label": {"category": "Technical", "urgency": "High"}}
{"ticket": "Can I change my profile picture?", "label": {"category": "Account", "urgency": "Low"}}

If you need better reasoning for edge cases, swap the model string to kimi-k2.6 or deepseek-v3.2 without changing any other code. Both are available on Oxlo.ai and use the same request-based pricing.

Next steps

Pipe the JSON output into a webhook or CRM queue to fully automate routing. You can also add a confidence threshold by asking the model for a third confidence key and sending low-confidence tickets to a human reviewer.

Top comments (0)