AI-Powered Return Analysis & Classification

01 Challenge

Free-text return comments contain the actual reasons – but Excel filters and RegEx fail on typos, nuances and contradictory statements.

02 Approach

A local AI pipeline: Qwen 2.5 14B runs in LM Studio, and a Python script classifies every comment into one of six categories via an OpenAI-compatible API.

03 Result

Free text becomes structured categories per item – an analysis from which product management, quality assurance and customer service can derive concrete actions.

Stack
PythonPandasLM StudioQwen 2.5 14Bn8n

Returns are the biggest “profit killer” in e-commerce. Particularly valuable – but often unused – are customers’ free-text comments. Statements like “Tight around the chest but too wide at the hips” can hardly be captured with simple Excel filters or classic keyword search algorithms (RegEx). Rigid rules often fail on typos alone (“too smal”) or on nuances.

In this project, I built a local AI pipeline that understands these comments semantically and categorizes them automatically.

Categories
6
2× fit, quality, visuals, preference, other
Parameters
14B
Qwen 2.5 Instruct, 4-bit quantized
External APIs
0
customer data stays local
Quantization
4-bit
runs on local hardware

Keyword search vs. language model

Excel filters & RegEx

  • Fails on typos like “too smal”
  • Reacts to single words like “fits” – without context
  • Unknown defects stay invisible as long as no keyword exists

Local LLM

  • Understands the comment semantically, typos included
  • “Actually fits well, but totally warped after washing” → QUALITY_DEFECT
  • Surfaces clusters of new defects without anyone searching for them

The Architecture

Instead of using external APIs like OpenAI (which raises privacy concerns), I run the model locally using LM Studio. This software provides an OpenAI-compatible server that we can control with Python.

  • Software: LM Studio (server)
  • Model: Qwen 2.5 14B Instruct (excellent performance in German, quantized)
  • Interface: Python script

Each comment is assigned to exactly one of six categories:

Category Meaning
FIT_ISSUE_SMALL Item smaller, shorter or tighter than expected
FIT_ISSUE_LARGE Item larger, longer or looser than expected
QUALITY_DEFECT Material, stitching, damage, odors
VISUAL_DISCREPANCY Color or style does not match the product photos
PREFERENCE Simply didn’t like it, no objective fault
OTHER Everything else

1. Technical Implementation

The connection uses the standard Python library, since LM Studio emulates OpenAI’s API structure. This makes the code extremely portable.

from openai import OpenAI
import pandas as pd
import tqdm

# Connection to the local LM Studio server
# Advantage: No costs, full data sovereignty & privacy
client = OpenAI(base_url="http://127.0.0.1:1234/v1", api_key="local-deployment")

def classify_smart(comment):
    # Optimized system prompt for precise classification
    system_prompt = """You are a Senior Quality Assurance Analyst for an E-Commerce brand.
    Your task is to analyze unstructured customer return feedback and identify the root cause.
    
    Classify the text into exactly one of the following technical categories:
    - FIT_ISSUE_SMALL (Indicates item is smaller/shorter/tighter than expected)
    - FIT_ISSUE_LARGE (Indicates item is larger/longer/looser than expected)
    - QUALITY_DEFECT (Material issues, stitching, damaged updates, odors)
    - VISUAL_DISCREPANCY (Color or style does not match product photos)
    - PREFERENCE (Customer simply didn't like it, no objective fault)
    - OTHER (Everything else)

    Responds strictly with the category name only."""
    
    try:
        response = client.chat.completions.create(
            model="model-identifier", # Uses the currently loaded model (e.g. Qwen 2.5)
            messages=[
                {"role": "system", "content": system_prompt},
                {"role": "user", "content": f"Feedback: '{comment}'"}
            ],
            temperature=0.0 # Temperature 0 for maximum determinism
        )
        return response.choices[0].message.content.strip()
    except Exception as e:
        return "ERROR"

# Load data
df = pd.read_csv('retouren_rohdaten.csv')

# Analyze a sample comment
sample = "Dachte das blau wäre heller, außerdem kratzt die Wolle."
print(f"Input: {sample}\nCategory: {classify_smart(sample)}")
# Output: QUALITY_DEFECT (defects prioritized over visual discrepancies)

2. Scaling & Integration (n8n)

This is a simplified code example (“proof of concept”). In a production environment, this script would ideally be integrated into an automation platform like n8n.

  1. 01New returnCustomer comment comes inShopify webhook
  2. 02OrchestrationWorkflow picks up the commentn8n
  3. 03ClassificationLocal model assigns a categoryLM Studio
  4. 04StorageStore the result per returnSheets / DB
  5. 05ReportAggregate categories per SKUPandas
Fig. 1 — Production workflow from the new return to the report

Modern quantized models (e.g. Qwen 2.5 14B with 4-bit quantization) are now extremely capable and offer an understanding that often goes beyond commercial cloud solutions.

# Iterate over the DataFrame with a progress bar
df['ai_category'] = [classify_smart(c) for c in tqdm.tqdm(df['customer_comment'])]

# Aggregate the results
report = df.groupby(['product_sku', 'ai_category']).size().unstack().fillna(0)

Business Value

Using the LLM delivers not just “data” but action items.

Content loop: Products with a high FIT_ISSUE_SMALL rate are flagged automatically so the content team can add a “runs small” note in the shop.

The categories map directly to individual teams:

  • Product management: Items with unusually many VISUAL_DISCREPANCY returns need better product photos or more accurate descriptions.
  • Quality assurance: A sudden increase in QUALITY_DEFECT for one supplier points to a problem in a production batch – before it spreads.
  • Customer service: Instead of a generic “we’re sorry,” the customer receives a response that fits their specific problem.

Privacy as an Advantage

Because the model runs locally, the pipeline is GDPR-compliant:

  • No customer data leaves the corporate network.
  • No data processing agreements with external AI providers necessary.
  • Full control over data retention and deletion.
  • No dependency on third-party API availability or pricing.

Conclusion

Data is useless if it doesn’t drive decisions. With local models like Qwen, business professionals can build powerful intelligence tools that don’t just manage returns but proactively prevent them. The result: real profitability through fewer returns and better supplier quality.