Teach a coding assistant the difference between zero stock and a blank
Write four expected rows before asking for code. Correct a misleading default and compare the result with a runnable Python converter.
22 min readAs of Nov 2026
Lesson guide · goals & preparation
By the end of this lesson
- Write a four-row input/output contract.
- Verify that zero and missing values take distinct paths.
Who this is for
- People reviewing an assistant’s first data-conversion script.
What you need
- You can follow the example just by reading table rows.
This lesson’s terms, in plain language
Read the short meanings here. Open a term for a fuller explanation and example.
- fallback
- An alternative path when the current process cannot finish the task.
1 / 4
Theory
Understand what to ask AI to do, how to ask, and the ideas behind the workflow.
When an empty cell becomes a stockout
Zero is a recorded observation. Blank is absent information. Turning both into zero can mark a real product out of stock. Start by specifying a few expected outputs a human can check, before asking the assistant to write any Python.
Hide the item IDs and count explicit zeroes. Exactly one accepted output row should contain zero. Now uncover the IDs to check which row holds it. A converter could swap P-11 and P-12 and still pass a test that counted zeroes without comparing identifiers. Compare the item and status together.
Describe the input contract with four small examples
A CSV record separates fields with commas. P-12 followed by a comma contains an empty second field; omitting the comma would mean the row is structurally short. This particular inventory counts individual pieces. After trimming whitespace, accept ASCII digits only. Fractions and negative numbers need review.
Illustration: An explicit zero taking the normal path while missing and invalid quantities go to review · AI Ping
- Distinguish an explicit stock count of zero from an empty field.
- Trim whitespace and check for missing input before testing for digits.
- Retain zero as a normal quantity. Assign separate review reasons to blanks and fractions.
Read every step as text
- The count column holds one real zero (P-11) and one empty cell (P-12). The faulty line fills the empty cell with "0", producing two zero rows. An uncounted item ships as a stockout.
- The or "0" default erases the fact that a value was missing before any check runs. Drop it and ask in order: empty, digits only, or anything else.
- P-10 holds 6: not empty, digits only. It is written as 6 with status ok.
- P-11’s 0 is an observed count: the shelf was checked and found empty. A valid quantity, it stays 0 with status ok.
- P-12 is an empty string once whitespace is trimmed. It is caught here, before the digit test: quantity left blank, status hold:missing.
- P-13 arrived with a value, 2.5, that breaks the whole-unit rule. Quantity blank, status hold:invalid. That calls for a different question than P-12.
- Four rows in, four rows out, same order, none deleted. Only P-11 has quantity 0, and the two held rows carry different reasons.
One tricky case is a cell holding only spaces. On screen it looks identical to a blank, yet the file stores space characters. Because the rule trims surrounding whitespace first, a spaces-only cell becomes an empty string and follows the missing path. Meanwhile a 6 padded with spaces still reads as 6 after trimming. Counting the characters you cannot see helps you explain a hold later.
Teaching v1 CSV with an intentionally empty field item count P-10 6 P-11 0 P-12 P-13 2.5
2 / 4
Step by step
Learn what to prepare, how to request help and how to revise the result through examples and explanations.
Ask for expected outputs before code
Request item, qty and status. Preserve every item, including records requiring review. Keep an independently written answer sheet: if the assistant invents the same rule in both its code and its tests, those tests can pass for the wrong reason.
The hard moment comes when the assistant's expected table disagrees with your own answer sheet. Do not simply trust one side. Find the first row where they split, then read the rule aloud for that row. If a blank quantity was marked hold:invalid, someone skipped the 'check for a value first' order. Fix that one row from the rule, re-lay the rest, and the whole table lines up for the same reason.
Example prompt Predict item,qty,status before writing code. Trim whitespace and accept only ASCII digits; normalise leading zeroes while preserving zero. Blank produces empty qty with hold:missing; other invalid values give empty qty with hold:invalid. Preserve all items in order. Teaching v1 CSV with an intentionally empty field item | count P-10 | 6 P-11 | 0 P-12 | P-13 | 2.5
Repair the default that silently invents zero
An editor’s defective line reads value = raw.strip() or "0". An empty string picks the fallback, erasing evidence that information was missing. Check emptiness before validating digits. A present yet invalid value calls for a different follow-up than an absent count.
Another trap when repairing the function is pushing the empty check to the end. Suppose you only write 'if it is digits, pass; otherwise hold:invalid.' An empty string is not digits, so it falls into invalid. Now an uncounted cell mixes with a genuinely wrong value, and the follow-up question changes. Ask about emptiness first, then digits, then the rest. Reorder them and the status column quietly drifts, so recheck all four rows.
Example prompt P-12 starts blank but the defective line turns it into zero. Change the quantity function to keep missing and known zero distinct. Recheck P-11 and P-13 as well.
Worked example & explanation Blank means hold:missing while zero is ok. The supplied fraction is present but violates the contract, so it is hold:invalid.
Read the working conversion and its output
The function trims surrounding whitespace, validates the entire string, then normalises leading zeroes. Only after validation may a digits-only zero become the canonical "0". Save the linked script and the source table as stock-v1.csv. Run python3 inventory_import.py v1 stock-v1.csv in that directory.
Illustration: Accepted quantities alongside two different review reasons · AI Ping To trust the function, push a value that is not in the table through it by hand. Feed it 010: no whitespace to trim, the digit test passes, and lstrip('0') removes only the leading zero to give 10. Zeroes in the middle or at the end stay, so the magnitude holds. For 00, every zero disappears, yet or '0' restores a single 0, and the status is ok. Tracing a value or two makes each line clearer than the table.
Expected rows, also produced by the example program item qty status P-10 6 ok P-11 0 ok P-12 hold:missing P-13 hold:invalid Download the example converter (Python)
Worked example & explanation This function comes from the accompanying Python program. The four rows above can be reproduced with that program.
Example codedef parse_quantity(raw): value = raw.strip() if value == "": return "", "hold:missing" if re.fullmatch(r"[0-9]+", value): return value.lstrip("0") or "0", "ok" return "", "hold:invalid"
3 / 4
Self-check
Think about what you would ask AI, then read the explanation. Written submissions and external AI use are optional.
This is a learning check, not a test you must pass. Use the explanations to understand the ideas.
Q1What are Q-1 and Q-2?
Write your thoughts (optional)
Your writing is not sent anywhere. It disappears when you leave or reload this page, so copy anything you want to keep.
Read the answer and explanation
Q-1 gives 3,ok and Q-2 gives 0,ok. The exercise normalises leading zeroes while preserving an observed zero.
This is your own review, not an automatic score.
Q2Do Q-3 and Q-4 have the same reason for review?
Write your thoughts (optional)
Your writing is not sent anywhere. It disappears when you leave or reload this page, so copy anything you want to keep.
Read the answer and explanation
Keep both quantities empty. Q-3 is missing; Q-4 contains a negative number that fails the digit rule.
This is your own review, not an automatic score.
Q3What evidence would you send for a Q-4-only failure?
Write your thoughts (optional)
Your writing is not sent anywhere. It disappears when you leave or reload this page, so copy anything you want to keep.
Read the answer and explanation
Supply Q-4,-1, its expected blank quantity and hold:invalid, plus the actual row. Preserve the other three expectations and rerun them after the fix.
This is your own review, not an automatic score.
Common mistakes
- A shared default destroys the distinction between absent and zero.
- Dropping invalid rows loses the item needing attention.
Your learning record
Completion is optional. Mark this lesson when you feel ready, or move to the next lesson without marking it.
Completion is saved in this browser.
4 / 4
Apply to your work
Consider how new material changes the workflow and checking criteria. Trying an external AI tool is optional.
Try four unfamiliar CSV records
For the Q records, write down a quantity and status for each row before running a tool. If the output differs, give the assistant the first failing input, expected row and actual row. That is a more useful revision request than asking it to rewrite the entire converter.
Before you start, draw three columns—item, qty, status. Take the Q rows from the top, asking the three questions in order: after trimming, is it blank; are the remaining characters only 0 through 9; or something else? Do not decide the answer in advance—follow where the rule sends each string. The leading sign in -1 and the front zero in 0003 reward a slow reading. Fill all four rows before you run the program or open the notes.
A fresh v1 file from another storeroom item count Q-1 0003 Q-2 0 Q-3 Q-4 -1
Write a note (optional)
Use this only if you want to record a prompt or your understanding. This is a notebook, not a connected AI assistant.
Your writing is not sent anywhere. It disappears when you leave or reload this page, so copy anything you want to keep.
References
- Getting good results from AI coding assistants — AI Ping
- csv — CSV file reading and writing — Python Software Foundation