Preserve leading zeros in CSV: an AI-assisted check
Preserve leading zeros in CSV with a four-item sample, a ready AI test prompt and a checked import-export round trip before accepting a product catalogue.

To preserve leading zeros in CSV files, treat product identifiers as text and test what survives an import and export. In fifteen minutes, you can build a small acceptance sample, check that 0042 remains different from 42, and use an AI assistant to draft tests without asking it to guess missing digits.
Imagine a small parts distributor sending a catalogue to a reseller. The stock counts look reasonable, yet two different items appear to have the same code. A spreadsheet may have interpreted their identifiers as numbers. The useful question is not how to make the column look tidy. It is whether the receiving process retains the original identifiers.
This guide covers a sample round trip, not a sales analysis or an automated catalogue repair. All products and codes below are invented. Content updated October 15, 2026.
Can you complete a useful sample in fifteen minutes?
Yes, if the goal is a checked sample rather than approval for a whole catalogue. Keep the source unchanged and work on a copy. Do not connect this exercise to your live shop. Create a plain text file containing the following rows and save it as a UTF-8 CSV. UTF-8 is a common text encoding; using the same encoding throughout helps keep product names readable.
part_id,description,units 0042,Small bracket,3 42,Large bracket,6 0009,Spare washer,8 B020,Storage tray,1
The deliberately similar identifiers are the point. If both first rows become 42, the test has detected a collision: two distinct identifiers have collapsed into one value. The descriptions help you notice the problem instead of accepting a plausible row count. Never use this fabricated list as a real catalogue update.
- Minutes one to three: save the source and note the four expected identifiers.
- Minutes four to eight: import the copy with the identifier column treated as text.
- Minutes nine to twelve: export a new CSV and inspect its contents in a text editor.
- Use the remaining time to record pass, fail, or not checked for each test.
This schedule is a suggested exercise, not a software performance claim. If the import controls are unfamiliar, stop at the unresolved step and record it. A partly completed checklist is more useful than an unsupported declaration that the process is safe.
Define what must stay unchanged
An identifier names a thing. A quantity measures how many things there are. That difference matters even when both contain digits. The code 0042 does not need arithmetic, while the units value 3 may later contribute to a stock total. Do not apply a blanket numeric conversion to both columns.
| Field | Rule for this exercise | Evidence to retain |
|---|---|---|
| part_id | Keep every character | 0042 and 42 remain distinct |
| description | Keep the item association | Small bracket stays with 0042 |
| units | Preserve the supplied quantity | 3, 6, 8 and 1 remain unchanged |
| Rows | No silent additions or removals | Four data rows, excluding the header |
Length alone is not enough: 0042 and 0099 have equal lengths but identify different things. Compare the characters and the associated description. If a tool sorts the rows, do not assume the second row still represents the same item. For this small sample, inspect each identifier and description together.
The Excel prompt collection helps with formulas and reporting instructions. This exercise belongs before those calculations: first establish that each row still refers to the intended part.
Choose an import route you can inspect
Microsoft documents importing identifier columns as Text. In a supported desktop Excel workflow, use Data and From Text/CSV, then the preview's transformation or editing option to set the identifier column to Text. Labels vary across versions. The important result is the column's treatment, not memorising one screenshot.
If the preview already shows 42 where your source says 0042, do not accept it. Changing an already altered value to text is not evidence that its original characters were recovered. Return to the source and review the automatic type-conversion step before loading. If you cannot locate that control, leave the import unapproved and use your version's help.
LibreOffice Calc provides a Text column type in its CSV import dialogue. This offers another route for the same sample, not a promise of compatibility with your destination system. Whichever application you choose, retain the original file and inspect the resulting values before continuing.
Ask AI for test cases, not repaired identifiers
Here AI means a text assistant you can ask to draft a checklist. You do not need to upload a real catalogue, buy a subscription, or enable spreadsheet editing for this task. If you are new to the approach, the practical artificial intelligence guide explains how to start with a small result you can review.
I am testing a CSV round trip. part_id is an exact text identifier; units is a quantity. Use only these fictional identifiers: 0042, 42, 0009, B020. Draft five test cases with input, expected output, a manual check, and a stop condition. Include a test that distinguishes 0042 from 42. Do not edit identifiers, add padding, infer missing digits, reorder records, or approve a real file. Ask when a business rule is missing.
Review the response as an untrusted draft. Does it compare exact characters, or merely say the column should look correct? Does it preserve the distinction between the first two codes? Does it invent a fixed identifier length that you never supplied? Reject those assumptions and request concrete expected outputs.
A helpful answer gives you a checklist you can execute. It cannot certify the exported file merely by describing good practice. Keep the test result separate from the generated instructions: one is a proposal, the other records what actually happened in your application.
Do not paste a confidential export just to obtain more realistic wording. The fictional sample already exposes the key failure. If you later need assistance with business data, handle permission and disclosure separately rather than treating this exercise as permission to upload it.
Test the exported file as well
Save the result to a new CSV filename. Open that output in a plain text editor before opening it through the spreadsheet again. Inspect the actual identifier fields and their descriptions. Then repeat the controlled import route. You are testing a round trip: source, spreadsheet, exported text, and re-imported sample.
Record five checks: all four identifiers match, their descriptions remain attached, quantities match, there are four data rows, and the re-import preserves the same distinctions. A blank result means not checked, not passed. A failed identifier comparison blocks the sample from acceptance even if the totals still look sensible.
If your destination application has a separate test-import environment, use that as the next stage. Check which existing item each row would update. Do not infer destination behaviour from a spreadsheet-only test. Guidance on low-stock alerts becomes relevant only after the item mapping is reliable.
What if the zeros are already missing?
The value 42 does not tell you whether the original was 42, 042, or 0042. Return to an authoritative source: an unchanged export, an approved product register, or the person responsible for identifiers. A documented fixed-width rule may support a separate recovery process. It should not be invented from a few examples.
Do not ask the assistant to pad every code to four characters. In our sample, that would incorrectly change the legitimate code 42 into 0042 and create the collision you were trying to prevent. A neat display is not the same thing as preserved source data.
Anar's essay about perfection versus effectiveness describes how chasing perfection delayed his own projects. The application here is a small verified test rather than an ambitious cleanup programme. This is an application of that published lesson, not a claim that he repaired this catalogue or achieved a measured result with it.
Leave a handoff another person can repeat
Write the source filename, application, import route, and expected sample values in a short handoff note. Add the result, unresolved test, responsible person, and next review date. If the export structure changes, repeat the test rather than assuming the old acceptance still covers it.
A spreadsheet change notification may help someone notice that a handoff document changed. It does not prove that the identifiers remain correct. Name the human reviewer and the specific comparison they must perform.
Once the identifier checks are complete, use the AI data analysis workflow for a separate reporting question. Today's deliverable is smaller: a preserved sample, a test checklist, and a stop rule. These give the next person something concrete to repeat before handling a larger export.
Frequently asked questions
Why do leading zeros disappear from CSV identifiers?
A receiving program may interpret a field as a number. Import the identifier as text and compare the result with the unchanged source.
Can AI recover the missing digits?
Not reliably without an authoritative source or an approved rule. Do not use a guessed identifier as a genuine product code.
Must I use a real catalogue for the first test?
No. The four fictional items are enough to test the selected route. Acceptance of the destination system and real catalogue requires separate checks.
Is a correct-looking spreadsheet enough?
No. Inspect the exported text and repeat the controlled import. A correct display does not certify the whole file or destination import.
Sources
Follow me on Instagram
Short notes, practical examples and daily digital strategy ideas.
I'm Anar Rustamli - a strategist, entrepreneur, and AI adoption leader working at the edge of growth, technology, and human thinking. Since 2016, my work has focused on helping businesses evolve in a rapidly changing digital landscape. I design growth systems, AI-powered workflows, and strategic frameworks that align performance with purpose. I believe real growth happens when strategy, data, and human insight work together - and my mission is to help businesses adopt AI in a way that strengthens both their results and their identity.

