DEV Community

shashank ms
shashank ms

Posted on

Using LLM for Text Analysis

We are building a feedback analysis agent that turns raw, unstructured customer comments into structured JSON. It helps product and support teams spot urgent issues and trending topics without reading every ticket manually.

What you'll need

Step 1: Configure the Oxlo.ai client

I start every project by verifying the client can reach the API. This snippet initializes the OpenAI SDK pointing at Oxlo.ai and sends a smoke-test request.

from openai import OpenAI

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

# Quick connectivity check
response = client.chat.completions.create(
    model="llama-3.3-70b",
    messages=[{"role": "user", "content": "ping"}],
)
print(response.choices[0].message.content)

Step 2: Write the analysis system prompt

The system prompt is the only training the agent gets. I keep it strict about output format so downstream code never has to guess.

SYSTEM_PROMPT = """You are a text-analysis assistant. Your job is to read a piece of customer feedback and return a single JSON object with exactly these keys:

- sentiment: one of "positive", "neutral", or "negative"
- topics: an array of up to three topics, e.g. ["billing", "onboarding"]
- urgency: one of "low", "medium", or "high"
- summary: a one-sentence summary of the feedback

Rules:
1. Output ONLY valid JSON. No markdown, no explanation.
2. If the text is not feedback, set sentiment to "neutral", topics to [], urgency to "low", and summarize anyway."""

Step 3: Create the analysis function with JSON mode

With the prompt locked, I wrap the call in a small function. I use JSON mode so the model is constrained to valid output, which saves me from writing a retry parser.

import json

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

Step 4: Process a batch of feedback records

Real data never arrives one line at a time. I loop over a list of raw strings, collect the structured results, and write them to a JSON Lines file for later analysis.

FEEDBACK_BATCH = [
    "I love the new dashboard, but exporting CSVs is still broken. Please fix it soon.",
    "Your onboarding wizard made setup trivial. Great work.",
    "I was charged twice this month and your refund page gives a 404. This is unacceptable.",
    "Meh. It works most days.",
]

with open("feedback_analysis.jsonl", "w") as f:
    for item in FEEDBACK_BATCH:
        result = analyze_feedback(item)
        record = {"input": item, "analysis": result}
        f.write(json.dumps(record) + "\n")
        print(record)

Step 5: Aggregate and display a summary report

Once the structured data is on disk, a second pass counts topics and flags anything marked high urgency. This is where the ROI shows up.

from collections import Counter

urgent_items = []
topic_counts = Counter()

with open("feedback_analysis.jsonl", "r") as f:
    for line in f:
        record = json.loads(line)
        analysis = record["analysis"]
        topic_counts.update(analysis.get("topics", []))
        if analysis.get("urgency") == "high":
            urgent_items.append(record["input"])

print("Topic breakdown:", dict(topic_counts))
print(f"High-urgency items: {len(urgent_items)}")
for item in urgent_items:
    print("-", item)

Run it

Save everything in analyze.py, set your API key, and run python analyze.py. The first pass writes feedback_analysis.jsonl; the second pass prints a summary like this:

Topic breakdown: {'billing': 1, 'export': 1, 'onboarding': 1, 'reliability': 1}
High-urgency items: 1
- I was charged twice this month and your refund page gives a 404. This is unacceptable.

Next steps

To productionize this, pipe the JSON Lines into a TinyDB or SQLite table so you can query trends over time. If your feedback is multilingual, swap the model to qwen-3-32b on Oxlo.ai and keep the same prompt. Because Oxlo.ai uses per-request pricing, long feedback threads do not inflate your bill the way token-based metering would. See https://oxlo.ai/pricing for details.

Top comments (0)