CSV for AI: Keep SKUs, Zeros, and Prices

Vladimir Lomtev•
CSV for AI: Keep SKUs, Zeros, and Prices

If, after processing a price list with AI, the item code 00123 turned into 123, first compare the original file, the data that went into the model, and the final export. The change may have happened when the file was opened in Excel, read from CSV, or assembled into the response. Keep identifiers as strings, explicitly set the price format, and pass these fields straight through from the source. Assign the model only the part of the work that requires text or meaning.

This analysis is intended for a product catalog specialist and an AI automation developer. It helps prepare a single supplier's CSV and find data transfer errors. Matching different products and selecting the corresponding 1C catalog item is a separate task; that topic is covered in the article on matching product nomenclature with AI.

The documentation was checked on November 2, 2026. The Python script shown here was run locally on sample files; the results and validation limits are described below. Excel and the AI service were not run while preparing this article. The sample names and prices were not taken from a client price list.

Contents:

Where the data changed

CSV is a text file with records and fields separated by a chosen character. The extension itself does not define business data types for your program’s columns. The same string of digits can represent either a price or an identifier. The delimiter, quotation marks, and parsing rules must be agreed on explicitly; differences between CSV files from different applications are described in the Python documentation.

Make a copy of the original export and open it in a text editor without saving any changes. Find the problematic SKU — the item code the system uses to identify a product. Then check that same field after import into your automation and after you receive the model’s response. Compare the actual values, not just how the cells are displayed.

Symptom What to compare Next action
In the source text 00123, after import 123 Column type in the importer Read the SKU as text and re-import the original
In the source file it is already 123, although 00123 is needed The export from the accounting system and an earlier copy
Obtain the correct source; do not guess the code length Instead of a long ID, an entry with E The original value and the formula bar value
Check whether only the display changed or the digits themselves The name split across two columns The delimiter and quotation marks in the record
Use a CSV parser with the required dialect The code is correct on input to the model, but changed in the response The request body and the result assembly rule

Remove model-driven rewriting of the code Do not pad all codes with zeros to the same length without the supplier's rule. 00123 and 123

may be two different products. If the original is lost, the correct result of this step is a list of unresolved rows for the catalog owner, not an automatically “fixed” price list.

How to import item codes into Excel without losing leading zeros Microsoft warns that Excel can remove leading zeros, convert long numbers, and limit numeric precision to 15 significant digits. For identifiers, the company recommends using text representation. Automatic conversion settings are available in Microsoft 365 and Excel 2024; do not assume they exist in older versions. Source: Microsoft Support

.

  1. Documented Power Query workflow:
  2. Select Data → From Text/CSV and choose the source file.
  3. Open the data transformation in the Query Editor. Button names depend on the version and interface language.
  4. Check the query steps: converting the SKU to a number must not happen before assigning the text type. Remove or fix the automatic type-change step if it is already numeric.
  5. Set the item code column type to Text and load the data. Find known 00123

and the long ID. Compare them with the source text before the next export. The basic import order and type assignment are confirmed by Microsoft's instructions

; checking the step order is necessary to work with the original values. This interface path was not tested here in an installed copy of Excel. A custom format such as 00000

solves the display problem. For exchange with an AI pipeline, you need the saved identifier, so check the exported file separately. Changing the format of a cell that is already damaged does not justify assuming the lost digits have been restored.

How to define a clear price list format for an AI pipeline For the sample, we will agree on three fields: sku , name , price_rub . Input is UTF-8, UTF-8 with BOM is acceptable; the delimiter is a semicolon. BOM is a service marker at the beginning of a file: the Python codec utf-8-sig skips it when reading if it is present. It does not automatically detect arbitrary encodings. .

Field Example rule Why it is needed
sku A non-empty string, no leading or trailing spaces, unique within the file Do not lose leading zeros or merge the answer with another product
name Non-empty text Provide the model with the original product name
price_rub A non-negative price in rubles: digits, comma, two digits Exclude guesswork about the currency and fractional part

This is the selected sample contract, not a universal pricing standard. It intentionally rejects 1 299,90, 1299.90, on request, negative values, and an empty price. If business needs require such values, define their meaning first, then update the validation. An empty price and a zero price must remain different states.

Save the following text as price.csv in a separate working folder:

sku;name;price_rub
00123;Blue mug;1299,90
123;"Travel mug;";0,00
000123456789012345;Steel thermos;2500,50

In the second record, the semicolon is part of the name, so the field is enclosed in quotes. Do not split lines with split(';'): this approach will treat part of the name as a new column. Do not fix the problem with a global replacement of delimiters — they may be part of the text itself.

How to convert CSV to JSON with explicit checks

The script below reads the agreed format, validates the records, and creates JSON — a text representation of structured data. SKU remains a string. The price is also stored as a string, but with a dot: this way the selected contract preserves two decimal places without an intermediate float. For calculations, the application will need to convert it separately into a consistent monetary type. In Python, Decimal is created directly from a string; the documentation explains how this differs from creating a decimal number from an already rounded binary float. Source: decimal.

You need Python 3 installed; no third-party packages are required. Save the code as prepare_price.py next to the practice CSV. Run it on a copy of the file, without customer data and without connecting to the accounting system.

import csv
import json
import re
import sys
from decimal import Decimal

source, target = sys.argv[1:3]
records = []
seen = set()

with open(source, encoding="utf-8-sig", newline="") as f:
    reader = csv.DictReader(f, delimiter=";", strict=True)
    if reader.fieldnames != ["sku", "name", "price_rub"]:
        raise ValueError("The columns sku;name;price_rub are required in this order")
    for number, row in enumerate(reader, start=1):
        if None in row or any(value is None for value in row.values()):
            raise ValueError(f"Record {number}: incorrect number of fields")
        sku, name, price = row["sku"], row["name"], row["price_rub"]
        if not sku or sku != sku.strip() or not name.strip():
            raise ValueError(f"Record {number}: empty field or spaces around SKU")
        if sku in seen:
            raise ValueError(f"Record {number}: duplicate SKU {sku!r}")
        if not re.fullmatch(r"[0-9]+,[0-9]{2}", price):
            raise ValueError(f"Record {number}: price must look like 1299,90")
        seen.add(sku)
        records.append({
            "sku": sku,
            "name": name,
            "price_rub": format(Decimal(price.replace(",", ".")), "f"),
        })

if not records:
    raise ValueError("The price list is empty")

# The x mode prevents overwriting an existing result.
with open(target, "x", encoding="utf-8") as f:
    json.dump(records, f, ensure_ascii=False, indent=2)
print(f"Done: {len(records)} records")

Reading with DictReader and opening with newline="" follow the CSV documentation. Exact price pattern matching is checked with re.fullmatch. Headers must match the sample, including order and case. Duplicate SKUs are treated as an error here: multiple offers for the same product with different warehouses require a different key and a different schema.

Run it from the working folder:

python3 prepare_price.py price.csv price.json

On Windows, the command may be called py instead of python3. If the sample runs successfully, the program outputs Done: 3 records and creates price.json. Result of the first record:

{
  "sku": "00123",
  "name": "Blue mug",
  "price_rub": "1299.90"
}

The entire file contains an array of three objects. ensure_ascii=False keeps Russian letters readable; serialization rules are described in the JSON documentation. Open the result in a text editor: the first and second records must have different SKUs, and the long code must preserve all characters.

What to do if validation stops

If the header is wrong, the number of fields is wrong, the SKU is duplicated, or the price is invalid, the script will end with an error. If the output file did not exist before, it will not be created until all records pass validation successfully. The existing price.json is not overwritten by the program: for a new run, choose a different name and explicitly point the downstream process to the needed result. After an unsuccessful run, you cannot treat the old file as a fresh export.

Message or situation Reason Fix
Columns are required in the specified order Different template or delimiter Check the header and export settings
Incorrect number of fields Extra column or missing value Correct the source record and export again
Duplicate SKU Duplicate row or the key is not specific enough Clarify the uniqueness rule; do not delete the row blindly
The price must look like 1299.90 The format does not match the contract Clarify the currency, precision, and allowed states
UnicodeDecodeError The file could not be read as UTF-8 Find out the encoding from the source and perform an explicit conversion

During article preparation, the check was limited to a local Python run: the training file was converted; preservation of leading zeros, long code, quotation marks, and the delimiter inside the name were verified separately. Duplicate SKU, an invalid price, extra and missing fields, an incorrect heading, and an empty price list all triggered a stop. The absence of overwriting an existing result was also verified. This is not a test of neural network quality, performance on a large price list, or import into Excel.

A strict parser will not catch every substantive error. A formally valid price may refer to a package instead of a single unit; an item number may belong to a different supplier. When combining multiple price lists, add supplier context and agree on a composite key. Do not apply the rules from this short example to XLSX, PDF, or arbitrary CSV without adaptation.

How to give the model only the work it needs to do

After preparing the data, set the generation boundary. For example, an application may need a draft description based on the product name and approved specifications. Save the SKU and price in the program, send the model only the allowed text fields, then attach its response to the original record. In a sequential flow, the program itself maintains the match; for parallel requests, you need your own task ID, which is not extracted from the generated text.

Do not ask the neural network to recover the SKU from the product name or to retype the entire price list just to add one new column. Even syntactically valid JSON requires verification against the source data. Treat product names as input data, not commands: the supplier's text should not change the application's rules or give the model permission to write prices into the live system.

For a no-code workflow, there is a separate guide to product descriptions from CSV in Dify. Here, the output is a prepared file with fields preserved; the model call and the upload back into the catalog remain the next, separately verified steps.

How Vladimir Lomtev's AI studio helps streamline price list transfer

In this task, data preparation is tied to content generation and business system integration. Vladimir Lomtev's AI studio can help align the product field schema, set up data transfer between the source and the AI process, and configure testing to ensure IDs and prices are preserved. These actions relate to data preparation, generative workflows, integration, and testing.

The first step is to choose one price list, its source, and its owner, then define the allowed changes and the success criteria: which fields must be preserved character for character and which ones may be generated. Discuss the task.

Where to start fixing it

Take one corrupted record and find the first mismatch with the source. If the original numbers are already lost, get a fresh export. If the corruption happens during reading, set the SKU to a string type and define explicit price rules. After local conversion, compare the result with the original and only then connect text generation. The working boundary is simple: the application preserves identifiers and monetary fields, while the model performs the agreed text task.

Request an audit

Share your contact details and we will follow up.

← All articles

Comments (0)

Loading comments…

Leave a comment
No registration required

Book a strategy call
for agentic operations

Tell us which workflow you want to improve. We will map feasibility, risks, and the fastest MVP path.

By submitting, you agree to our privacy policy

Contacts

Global Operations

Serving U.S. clients remotely
with private cloud and on-prem options

Strategy calls by request

We respond after reviewing your workflow context.

info@agentsunrise.pro

For partnership inquiries

Have a proposal?

Write to us in messengers

© 2026 AgentSunrise