Introduction
A growing distributor wants managers to ask questions in plain English: "Which orders are stuck?" "How many quotes did we lose last quarter?" The team connects an LLM to a read replica, writes a system prompt, and tries some questions. The answers are fluent and wrong.

A quick look at the orders table explains why. The status column contains "Open," "open," "OPEN - awaiting stock," "Pending," "Hold," "on hold," "Done," "Completed," "closed," "Cancelled," "cancel," and 23 other values. Staff know that "hold" means a credit hold and "on hold" means the customer asked to pause. The model does not, and neither does anyone new.

In this article you will learn how to find inconsistent labels, design a canonical status model, migrate existing data safely, enforce it going forward, and give AI tools a clean, documented layer to query.

Step 1: Inventory What You Actually Have
Start by measuring the problem. For each important table, list every distinct value of status-like fields with counts and the date range in which each value was used.

SELECT status,
count(*) AS rows,
min(created_at) AS first_seen,
max(updated_at) AS last_seen
FROM orders
GROUP BY status
ORDER BY rows DESC;

Look beyond the column named status. Stage, state, type, priority, and category fields often have the same problem. Also check for flags that overlap with status, such as an is_cancelled boolean that disagrees with a status of "Shipped."

Step 2: Define a Canonical Status Model
With the people who use the data, define a small set of statuses with written meanings. Separate dimensions that have been mixed together. "OPEN - awaiting stock" combines a lifecycle status (open) with a reason (awaiting stock); store them in two fields. "Hold" and "on hold" become one status, on_hold, with a hold_reason of credit or customer_request.

Write each status as a sentence: "shipped: all lines have left the warehouse, and a delivery note exists." These definitions become part of the context you give an AI tool later, and they settle arguments between teams now.

Step 3: Map and Migrate Existing Data
Create a mapping table from every legacy value to the new status and reason, and review it with the business before running anything. Some legacy values will be ambiguous; resolve them with other fields, such as shipment records, or route them to a short manual review.

CREATE TABLE status_map (
legacy_value text PRIMARY KEY,
new_status order_status NOT NULL,
hold_reason text
);
UPDATE orders o
SET status_v2 = m.new_status, hold_reason = m.hold_reason
FROM status_map m
WHERE lower(trim(o.status)) = m.legacy_value
AND o.status_v2 IS NULL;

Run the migration with the expand-contract approach: add the new columns, write both old and new from the application, backfill in batches, then switch reads. Keep the original value in an archived column for traceability.

Step 4: Enforce It Going Forward
Cleanup is wasted if new bad values arrive next week. Use a Postgres enum type, a check constraint, or a foreign key to a statuses table so the database rejects anything else. Replace free-text status inputs in the UI with dropdowns, and validate statuses in every API and import path, including CSV uploads and integrations.

Step 5: Give AI Tools a Clean Semantic Layer
Do not point an LLM at raw tables. Create read-only views with clear names and columns, such as open_orders or lost_quotes_last_90_days, and a data dictionary describing each view, column, and status in plain language. Grant the AI tool's database role access to those views only. This reduces wrong answers and limits what a bad query can touch.

Practical Examples: Real-World Use Cases
A B2B electronics distributor found 41 distinct order status values. After mapping them to seven statuses and two reason fields, its natural-language reporting assistant matched finance's numbers on a test set of 50 questions, where it had matched fewer than half before.

A services company cleaned its CRM deal stages, which had drifted across three sales teams. The same cleanup fixed its forecast report, which had been double-counting deals labelled "Verbal" in one team and "Commit" in another.

A manufacturer created a support_tickets_clean view with normalized priorities and statuses before enabling an AI summary feature. Engineers could change the underlying tables without breaking the AI integration.

Common Mistakes to Avoid

  • Asking the LLM to interpret messy labels through prompt instructions. It will be inconsistent across questions.

  • Mapping values without involving the people who created them.

  • Cleaning historical data but leaving free-text inputs in the UI.

  • Combining lifecycle status and reason in one field again.

  • Giving AI tools access to every table instead of a curated set of views.

Best Practices: Actionable Tips

  • Inventory distinct values for every status-like field in your top five tables this week.

  • Keep canonical statuses to the smallest set that supports real decisions.

  • Store definitions in a data dictionary that both people and AI tools can read.

  • Build a test set of real questions with known answers and run it after every data change.

  • Monitor for new distinct values with a scheduled query, and alert when one appears.

Conclusion
LLMs cannot reliably interpret data that people themselves need tribal knowledge to read. Before connecting AI to your database, inventory status values, define a small canonical model with written meanings, migrate and enforce it, and expose clean, documented views. The takeaway: data cleanup is the first AI project, and it pays off even if you never ship the AI feature.

_Prepare Your Data for AI With Parallaxis
_
Parallaxis helps B2B companies get their operational data ready for automation and AI, from status cleanup and schema migrations to secure semantic layers for LLM tools. If you want AI answers your team can trust, visit parallaxis.in to explore our automation services or talk to us about your data.