DEV Community

shashank ms
shashank ms

Posted on

Unlocking Language Understanding with LLMs

We are going to build a customer feedback analyzer that reads unstructured support tickets and extracts structured data like sentiment, category, and urgency. This helps support teams prioritize queues without reading every message manually. Because Oxlo.ai charges a flat rate per request, you can feed it long ticket threads or multi-turn conversations without watching the cost climb.

What you'll need

Step 1: Test the connection

Before we parse anything, we verify that the client can reach Oxlo.ai and that the API key is active. I always do this with a trivial completion to avoid debugging auth issues later.

from openai import OpenAI

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

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

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

Step 2: Write the system prompt

The system prompt is the contract between us and the model. It defines exactly what language understanding means for this project: extract five specific fields and return nothing else.

SYSTEM_PROMPT = """You are a language understanding engine.
Analyze the customer support ticket and extract these fields in JSON format:
- sentiment: one of [positive, neutral, negative]
- category: one of [billing, technical, account_access, feature_request, other]
- urgency: one of [low, medium, high, critical]
- summary: a one-sentence summary of the issue
- action: the single best next step for a human agent

Respond with valid JSON only. No markdown, no explanation."""

Step 3: Build the analyzer function

Now we wrap the API call in a function that accepts a raw ticket string, sends it to Oxlo.ai, and returns a Python dict. I use Llama 3.3 70B here because it follows structured instructions reliably and handles long ticket threads well.

import json
from openai import OpenAI

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

SYSTEM_PROMPT = """You are a language understanding engine.
Analyze the customer support ticket and extract these fields in JSON format:
- sentiment: one of [positive, neutral, negative]
- category: one of [billing, technical, account_access, feature_request, other]
- urgency: one of [low, medium, high, critical]
- summary: a one-sentence summary of the issue
- action: the single best next step for a human agent

Respond with valid JSON only. No markdown, no explanation."""

def analyze_ticket(ticket_text: str) -> dict:
    response = client.chat.completions.create(
        model="llama-3.3-70b",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": ticket_text},
        ],
        response_format={"type": "json_object"},
    )
    raw = response.choices[0].message.content
    return json.loads(raw)

Step 4: Process a batch of tickets

Support queues do not arrive one at a time. This loop runs every ticket through the analyzer and stores the results in a list so we can build a simple report.

tickets = [
    "I was charged twice for my Pro plan this month. Please fix this immediately.",
    "How do I export my data to CSV? The docs mention a button I cannot find.",
    "Your API is down again. This is the third outage this week and we are losing customers.",
]

results = [analyze_ticket(t) for t in tickets]

for r in results:
    print(r)

Step 5: Filter and route urgent items

Language understanding is only useful if it changes what we do next. This snippet pulls out anything marked high or critical so a human agent can jump on it first.

def route_urgent(results: list[dict]) -> list[dict]:
    flagged = [r for r in results if r.get("urgency") in ("high", "critical")]
    for item in flagged:
        print(f"URGENT [{item['category']}]: {item['summary']}")
        print(f"Suggested action: {item['action']}\n")
    return flagged

urgent = route_urgent(results)

Run it

Putting it all together, the finished script looks like this.

import json
from openai import OpenAI

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

SYSTEM_PROMPT = """You are a language understanding engine.
Analyze the customer support ticket and extract these fields in JSON format:
- sentiment: one of [positive, neutral, negative]
- category: one of [billing, technical, account_access, feature_request, other]
- urgency: one of [low, medium, high, critical]
- summary: a one-sentence summary of the issue
- action: the single best next step for a human agent

Respond with valid JSON only. No markdown, no explanation."""

def analyze_ticket(ticket_text: str) -> dict:
    response = client.chat.completions.create(
        model="llama-3.3-70b",
        messages=[
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": ticket_text},
        ],
        response_format={"type": "json_object"},
    )
    return json.loads(response.choices[0].message.content)

def route_urgent(results: list[dict]) -> list[dict]:
    flagged = [r for r in results if r.get("urgency") in ("high", "critical")]
    for item in flagged:
        print(f"URGENT [{item['category']}]: {item['summary']}")
        print(f"Suggested action: {item['action']}\n")
    return flagged

if __name__ == "__main__":
    tickets = [
        "I was charged twice for my Pro plan this month. Please fix this immediately.",
        "How do I export my data to CSV? The docs mention a button I cannot find.",
        "Your API is down again. This is the third outage this week and we are losing customers.",
    ]

    results = [analyze_ticket(t) for t in tickets]
    route_urgent(results)

When I ran this against Oxlo.ai, the output looked like this.

URGENT [billing]: Customer reports being double charged for the Pro plan this month.
Suggested action: Refund the duplicate charge and confirm the fix to the customer.

URGENT [technical]: API has experienced a third outage this week impacting the customer's business.
Suggested action: Escalate to the SRE team immediately and provide a post-incident timeline.

Wrap-up

You now have a working language understanding pipeline that turns raw text into structured, actionable data. Two concrete next steps: wire the route_urgent function into a Slack webhook so critical tickets ping a channel automatically, or swap the model to qwen-3-32b on Oxlo.ai if you need to analyze tickets in multiple languages.

Top comments (0)