DEV Community

shashank ms
shashank ms

Posted on

LLM for Intent Detection

Intent detection is the backbone of conversational AI, search routing, and agentic tool selection. Traditional NLP pipelines rely on rigid regex patterns or small classifier models that fracture when users deviate from expected phrasing. Large language models absorb context, slang, and implicit goals in a single forward pass, turning intent classification from a brittle rules engine into a robust reasoning task. For teams running high-volume classification workloads, inference economics matter as much as accuracy. Oxlo.ai offers a developer-first platform with flat per-request pricing, meaning your cost per intent classification stays constant whether the user drops a ten-word query or a ten-thousand-word transcript.

Why LLMs for Intent Detection

Rule-based intent classifiers require meticulous upkeep. Every new user goal demands fresh regex, updated synonym lists, and retrained embeddings. LLMs invert this cost. A model such as Qwen 3 32B or Llama 3.3 70B can parse instructions, infer implicit goals, and return structured labels without gradient updates. Because intent detection often sits upstream of tool use or RAG retrieval, accuracy here directly impacts downstream pipeline quality. Oxlo.ai provides fully OpenAI SDK compatible access to these models with no cold starts, so classification latency stays predictable from the first request.

Prompt Engineering for Intent Classification

The difference between a flaky classifier and a reliable one is usually the prompt. Give the model a constrained output schema, a clear taxonomy, and a few in-context examples. For production systems, JSON mode eliminates parsing drift.

import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.oxlo.ai/v1",
    api_key=os.environ["OXLO_API_KEY"]
)

SYSTEM_PROMPT = """
You are an intent classifier. Given a user message, return a JSON object with:
- intent: one of [SUPPORT, BILLING, SALES, TECHNICAL]
- confidence: a float between 0 and 1
- reasoning: one sentence explaining why
"""

user_message = "I was charged twice last month and I can't access my dashboard."

response = client.chat.completions.create(
    model="Qwen 3 32B",
    messages=[
        {"role": "system", "content": SYSTEM_PROMPT},
        {"role": "user", "content": user_message}
    ],
    response_format={"type": "json_object"}
)

print(response.choices[0].message.content)

Multi-Intent and Ambiguity

Real users rarely express exactly one intent. A message like "I want to upgrade my plan but I also need a refund for last month" blends SALES and BILLING. A classifier that forces mutually exclusive labels will fail. LLMs can return ranked intent lists, confidence distributions, or structured arrays. For ambiguous or deeply nested requests, reasoning models such as DeepSeek R1 671B MoE or Kimi K2.5 can apply chain-of-thought reasoning before committing to a label. On Oxlo.ai, these models are available through the same chat/completions endpoint, so upgrading classification logic does not require swapping client libraries.

Production Considerations

Three factors dominate production intent detection: latency, context window, and cost.

Latency. Oxlo.ai serves popular models with no cold starts, which keeps p50 latency stable even during traffic spikes.

Context. Some pipelines classify intent across entire conversation threads or lengthy documents. DeepSeek V4 Flash supports a 1M context window, and Kimi K2.6 handles 131K tokens, both available on Oxlo.ai.

Cost. Token-based providers scale cost with input length. If your classifier ingests long transcripts or multi-turn history, token bills grow linearly. Oxlo.ai uses flat per-request pricing. For long-context workloads, request-based pricing can be 10-100x cheaper than token-based alternatives. See https://oxlo.ai/pricing for current plan details.

Implementation with Oxlo.ai

Because Oxlo.ai is a fully OpenAI SDK compatible drop-in replacement, you can migrate an existing intent pipeline by changing two lines: the base URL and the API key. The platform supports streaming responses, function calling, and JSON mode, all of which are useful for intent detection systems that must trigger downstream tools.

import os
from openai import OpenAI

client = OpenAI(
base_url="https://api.oxlo.ai/v1",
api_key=os.environ["OXLO_API_KEY"]
)

tools = [
{
"type": "function",
"function": {
"name": "route_to_department",
"description": "Route the user to the correct department",
"parameters": {
"type": "object",
"properties": {
"department": {
"type": "string",
"enum": ["support", "billing", "sales"]
}
},
"required": ["department"]
}
}
}
]

response = client.chat.completions

Top comments (0)