top of page

How to detect outliers with ChatGPT using IQR and z-score checks

2 minutes ago
8 min read
Cover with the title How to detect outliers with ChatGPT using IQR and z-score checks over a teal city skyline, Data Studios original cover

ChatGPT's data analysis feature can flag outliers in an uploaded CSV or spreadsheet by writing and running Python code, and OpenAI's help documentation lists outlier values among the data issues it can find and repair, next to missing values, duplicate rows and incorrect data types. The flags it returns are only as good as the rule behind them, and the two rules analysts reach for most often, the interquartile range (IQR) fence and the z-score, can disagree sharply on the same column.


The disagreement is easy to reproduce. On the 15-order illustrative dataset used below, the IQR rule flags three orders, while the classic "absolute z-score above 3" rule flags only one, because the largest value inflates the standard deviation enough to hide the second-largest. An analyst who accepts the first answer ChatGPT gives without asking which rule it used can end up deleting one bad record and keeping two.


The method that follows asks ChatGPT for a named rule, makes it show the thresholds and the code, and compares its output with results computed independently in Python, so every flagged row can be checked before anything is removed or corrected.


··········


OUTLIER DETECTION: WHEN ANALYSTS NEED IT AND WHICH RULE TO ASK FOR.


Outlier checks come up whenever a dashboard average looks wrong, a monthly total jumps without a business reason, or a dataset arrives from a system that allows free-text entry of amounts. Typical causes are data entry errors (an extra zero, a misplaced decimal), test transactions left in production data, refunds stored as small positive values, unit mix-ups and genuine but rare events such as a bulk order. Statistics cannot tell these apart. A rule can only point to values that sit far from the rest, and a person who knows the business decides what each one is.


Three rules cover most practical cases. The IQR fence marks values below Q1 minus 1.5 times the IQR or above Q3 plus 1.5 times the IQR, where Q1 and Q3 are the first and third quartiles. Because quartiles ignore the extremes, the fence holds steady even when the data contains several large errors. The z-score measures how many standard deviations a value sits from the mean, and the usual cutoff is an absolute value above 3. It works well on large, roughly bell-shaped data, but the mean and standard deviation are themselves pulled by the outliers, which makes it unreliable on small or skewed samples. The modified z-score replaces the mean with the median and the standard deviation with the median absolute deviation (MAD), using the formula 0.6745 times the distance from the median divided by the MAD, with a common cutoff of 3.5.


For order values, transaction amounts and other skewed business measures, the IQR fence or the modified z-score is the safer default. Asking for one rule by name, and for the thresholds it produced, keeps ChatGPT from silently choosing for you.


··········


CHATGPT DATA ANALYSIS REQUIREMENTS AND FILE LIMITS FOR OUTLIER CHECKS.


The limits below come from OpenAI's help center pages on data analysis with ChatGPT and on file uploads, verified on November 19, 2026. The data analysis page describes a code environment preloaded with hundreds of Python libraries, with pandas used for tables and Matplotlib for charts. It does not list which ChatGPT plans include data analysis, so check the features shown in your own workspace.


........


Item

What OpenAI documents

Supported data files

Excel (.xls, .xlsx), CSV, PDF, JSON

Files per conversation

Up to 10

Per-file hard limit

512 MB

CSV and spreadsheets

About 50 MB, depending on row size

Free users

Up to 3 file uploads per day

Storage caps

10 GB per end user, 100 GB per organization

Code environment

Destroyed within 13 hours of inactivity

Interactive charts

Bar, pie, scatter and line in most cases


........


Two documented details shape an outlier workflow. Box plots and histograms, the usual charts for spotting extremes, are rendered as static images, so selecting a point on them is not possible. And the code environment has no network access, so the file you upload is the only data the analysis can see. Files larger than the spreadsheet limit need to be split or sampled first, a process covered in our guide on analyzing a CSV over ChatGPT's 50MB limit.


OpenAI's help page on model training states that content from ChatGPT Team, ChatGPT Enterprise and the API Platform is not used for training by default, while content from individual ChatGPT services may be used unless the user opts out in the data controls or through OpenAI's privacy portal. Order-level data with customer identifiers should follow your company's policy before it is uploaded, and removing names, emails and account numbers from the file is a simple first step.


··········


WORKED EXAMPLE: AN ILLUSTRATIVE ORDERS FILE WITH THREE SUSPECT VALUES.


The table below is an illustrative dataset of 15 orders. Most order values sit between 185 and 247 dollars. Three rows were planted to imitate common errors: an order of 4,150, one of 2,210 and one of 12.


........


order_id

region

order_value

A101

East

212

A102

West

198

A103

East

240

A104

South

185

A105

West

226

A106

East

4150

A107

South

205

A108

West

231

A109

East

190

A110

South

218

A111

West

12

A112

East

247

A113

South

201

A114

West

2210

A115

East

224


........


Save it as a CSV with the header row exactly as shown. OpenAI's documentation recommends descriptive column headers in the first row and one row per record, and warns against several tables on one sheet or empty rows and columns, all of which make the generated code less reliable.


Upload the file and start with a prompt that fixes the rule, the column and the output format:


Use the uploaded orders file. Column order_value contains order amounts in USD.
1. Compute Q1, Q3 and the IQR of order_value with pandas default quantiles.
2. Flag rows below Q1 - 1.5*IQR or above Q3 + 1.5*IQR.
3. Return a table with order_id, order_value and the lower and upper fence.
Do not delete or change any rows. Show the Python code you ran.

Then ask for the two comparison rules in a second prompt, so the results can be put side by side:


On the same column, also compute:
- the z-score using the sample standard deviation, flagging |z| > 3
- the modified z-score 0.6745 * (x - median) / MAD, flagging |value| > 3.5
Add one column per rule (True/False) and list the flagged order_ids for each rule.

OpenAI's documentation explains that the code behind a response can be opened through the "View Analysis" link or the code icon and copied. Open it and confirm that the quantile method, the standard deviation and the cutoffs match what the prompts asked for.


··········


THE CORRECT RESULT: IQR FENCES, Z-SCORES AND MODIFIED Z-SCORES.


The figures below were computed in Python with pandas on the illustrative data. ChatGPT's output for the same prompts should match them; if it does not, the code view will show which step differs.


........


Statistic

Value

Mean order value

596.60

Median order value

218.00

Sample standard deviation

1,112.44

Q1 / Q3 (pandas default)

199.50 / 235.50

IQR

36.00

Lower / upper fence

145.50 / 289.50

Median absolute deviation

20.00


........


The three rules then flag these rows:


........


order_id

order_value

IQR flag

z-score

z flag

Modified z

Modified z flag

A106

4150

Yes

3.19

Yes

132.61

Yes

A114

2210

Yes

1.45

No

67.18

Yes

A111

12

Yes

-0.53

No

-6.95

Yes


........


The IQR fence and the modified z-score flag the same three orders. The z-score rule flags only A106. The mean of 596.60 is about 2.7 times the median because of the two large values, and the standard deviation of 1,112.44 is so wide that an order of 2,210 lands only 1.45 standard deviations above the mean, while an order of 12 appears slightly below average. This effect, called masking, is the main reason the plain z-score is a poor default for small business datasets.


The impact on reporting is large. The total of all 15 orders is 8,949 dollars. Excluding the three flagged rows leaves 12 orders totaling 2,577 dollars, with a mean of 214.75 and a median of 215.00. A dashboard showing an average order of 596.60 would overstate the typical order by roughly 2.8 times.


The quartile method can change the fences slightly. Python's statistics module with the exclusive method gives Q1 of 198, Q3 of 240 and fences of 135 and 303, against 145.50 and 289.50 with the pandas default, and the same three orders are flagged under both. When ChatGPT's fences differ from yours, ask which quantile method it used before assuming an error.


The code below reproduces every figure above and can be run locally to check ChatGPT's work:


import pandas as pd

df = pd.read_csv("orders.csv")
v = df["order_value"]

q1, q3 = v.quantile(0.25), v.quantile(0.75)
iqr = q3 - q1
lower, upper = q1 - 1.5 * iqr, q3 + 1.5 * iqr
df["iqr_flag"] = (v < lower) | (v > upper)

df["z"] = ((v - v.mean()) / v.std()).round(2)
df["z_flag"] = df["z"].abs() > 3

med = v.median()
mad = (v - med).abs().median()
df["mod_z"] = (0.6745 * (v - med) / mad).round(2)
df["mod_z_flag"] = df["mod_z"].abs() > 3.5

print(q1, q3, iqr, lower, upper, mad)
print(df[df["iqr_flag"] | df["mod_z_flag"]])

··········


REVIEWING CHATGPT OUTLIER FLAGS BEFORE CHANGING THE DATA.


The errors that appear most often in AI-generated outlier checks are predictable. A rule may be applied that the prompt did not request, often the z-score because it is the textbook default. The population standard deviation may be used where the sample standard deviation was asked for, which shifts every z-score slightly. Rows may be dropped or capped without being asked, especially after a prompt such as "Check this data for common issues", which OpenAI's documentation describes as a way to have ChatGPT find and repair problems. And amounts stored as text, with currency symbols or thousands separators, may be silently converted or excluded, changing the row count before any rule runs.


A short checklist catches these problems. Confirm the row count before and after the check, which should be 15 in the example. Compare the median, quartiles and fences with your own calculation. Open the code view and read the lines that compute the thresholds. Ask ChatGPT to return the flagged rows as a separate table and leave the original file unchanged, so you can export both. The same row-count discipline appears in our guide on cleaning and deduplicating a CSV with ChatGPT.


Outliers in grouped data need a group-level check. A 2,210-dollar order can be normal for a wholesale region and an error for a retail one, so ask ChatGPT to compute the fences per region or per product line when the groups have different typical values, and keep in mind that small groups give unstable quartiles.


The decision on each flagged value stays with a person who can check the source system. Each flag can mean an entry error to correct, a test or duplicate record to remove, or a legitimate large order to keep and report separately. Record the decision and the reason next to the order_id, so the same row is not reviewed again next month. Broader file-handling behavior is described in our article on whether ChatGPT can analyze CSV files.


··········


OUTLIER DETECTION IN CHATGPT: DOCUMENTED FACTS AND OPEN POINTS.


OpenAI documents that ChatGPT data analysis runs Python with pandas on uploaded Excel, CSV, PDF and JSON files, accepts up to 10 files per conversation with CSV and spreadsheet files limited to about 50 MB, and can find outlier values as part of its data-issue checks. The code behind each answer can be opened and copied, which makes every threshold verifiable.


What OpenAI does not document is which statistical rule ChatGPT applies when a prompt does not name one, or which plans include data analysis. Both points argue for prompts that name the rule, the quantile method and the cutoff, and for a local recomputation of the fences on any dataset that feeds a report.


On the illustrative orders file, the IQR fence and the modified z-score flag the same three orders, while the plain z-score finds one of them. For skewed business measures on small and mid-sized datasets, asking ChatGPT for the IQR rule or the modified z-score, then reviewing every flagged row against the source system before any change, gives results that hold up in a dashboard review.


··········


FOLLOW US FOR MORE.


·····


DATA STUDIOS


·····


datastudios.org


bottom of page