DEV Community

shashank ms
shashank ms

Posted on

The Role of LLM in Natural Language Processing

We are going to build a support ticket triage agent that ingests raw customer emails and returns structured NLP analysis: sentiment, category, named entities, urgency, a summary, and a draft reply. This replaces a classical multi-model NLP pipeline with a single LLM call. Because the input can grow quickly with long email threads, Oxlo.ai's flat per-request pricing keeps costs predictable regardless of token count, which makes it a strong fit for this workload.

What you'll need

You can view Oxlo.ai's pricing at https://oxlo.ai/pricing. The request-based model means a 50-word ticket and a 5,000-word thread cost the same flat amount, so you do not need to truncate context to save money.

Step 1: Configure the Oxlo.ai client

Point the OpenAI SDK at Oxlo.ai's endpoint. I use llama-3.3-70b here because it follows instructions reliably and outputs clean JSON. Oxlo.ai serves this with no cold starts, so the first request is as fast as the tenth.

from openai import OpenAI

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

Step 2: Define the NLP system prompt

The prompt encodes four classical NLP tasks, text classification, named entity recognition, summarization, and response generation, into one JSON schema. Keeping this in the system message separates the pipeline instructions from the user data.

SYSTEM_PROMPT = """You are an NLP triage engine. Analyze the customer support ticket and return a single JSON object with these exact keys:

- "sentiment": one of "angry", "frustrated", "neutral", "satisfied"
- "category": one of "billing", "technical", "feature_request", "account", "other"
- "entities": an object with keys "product_name" and "account_email". Use null if a value is missing.
- "urgency": one of "low", "medium", "high"
- "summary": a concise 20-word summary of the problem
- "draft_reply": a brief 40-word professional response

Rules:
1. Return only valid JSON.
2. Do not wrap the output in markdown code fences.
3. Infer the product_name from context if it is not explicit."""

Step 3: Write the triage function

This function takes a raw ticket string, sends it to Oxlo.ai, and parses the JSON result. I keep the parsing strict so that any malformed response surfaces immediately during testing.

import json

def triage_ticket(ticket_text: str) -> dict:
    if not ticket_text or not ticket_text.strip():
        raise ValueError("ticket_text must not be empty")

    user_message = ticket_text

    response = client.chat.completions.create(
        model="llama-3.3-70b",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": user_message},
        ],
    )

    raw = response.choices[0].message.content
    return json.loads(raw)

Run it

Here are two sample tickets. The first is a short billing complaint, and the second is a longer technical thread. On Oxlo.ai, both cost the same flat per-request rate even though the second input is much larger.

tickets = [
    "I was charged twice for ProPlan last month. My email is alice@example.com. Please fix this immediately.",
    "Hi, I have been trying to export my data from your dashboard for three days. Every time I click 'Export CSV' the spinner loads forever and then I get a 504 gateway timeout. I am on the Enterprise tier and this is blocking our quarterly report. My account is bob@company.dev. We need this resolved by Friday or we will have to look elsewhere.",
]

for t in tickets:
    result = triage_ticket(t)
    print(json.dumps(result, indent=2))
    print("---")

Running the script produces structured output like this:

{
  "sentiment": "frustrated",
  "category": "billing",
  "entities": {
    "product_name": "ProPlan",
    "account_email": "alice@example.com"
  },
  "urgency": "high",
  "summary": "Customer was double-charged for ProPlan and requests immediate correction.",
  "draft_reply": "Thank you for reaching out. We sincerely apologize for the duplicate charge on your ProPlan account. Our billing team is reviewing this now and will issue a refund within 24 hours."
}
---
{
  "sentiment": "angry",
  "category": "technical",
  "entities": {
    "product_name": "Dashboard Export",
    "account_email": "bob@company.dev"
  },
  "urgency": "high",
  "summary": "Enterprise customer unable to export CSV due to 504 errors for three days, blocking quarterly report.",
  "draft_reply": "We understand how critical this export is for your quarterly report. Our engineering team is investigating the 504 timeout on the CSV export feature and will provide an update within the next two hours."
}

Wrap-up

You now have a single LLM agent that replaces four separate classical NLP components. If you want to push this further, wire the triage_ticket function into a FastAPI endpoint so your support desk can call it in real time, or add a feedback loop where high-urgency tickets trigger a Slack alert automatically.

Because this agent can receive long, unpredictable email threads, Oxlo.ai's request-based pricing is a genuinely practical choice. You get the full context window of models like llama-3.3-70b or kimi-k2.6 without watching token meters run up on every long ticket.

Top comments (0)