Builder tools
Use Codex to Build a Small CSV Report with Tests and a Dry Run
Summary
Cihan's view: Give Codex a bounded CSV task, require a dry-run output and tests, inspect the diff, and compare the report with hand-checked sample totals before using real data.
What you will make
A small local Python utility that reads a fictional sales CSV and writes a separate weekly exception report. The report will flag missing regions, negative quantities, and rows with an unknown product code. It will not edit the input file or send the report anywhere.
This is an advanced builder lesson. It assumes a terminal, a local project folder, Python, and Codex CLI access. OpenAI’s Codex CLI documentation describes Codex as a terminal tool that can inspect files, make changes, run commands, and support repeatable workflows. The files in this guide are fictional, and the report shape below is an editor-written example. One real Codex run of the three prompts is recorded in the section “What happened when I ran it”.
No-code alternative
If you do not use a terminal, upload the same CSV to an approved ChatGPT account and ask for an exception table. Check the totals yourself and keep the output separate from the original file. The no-code route is useful for one report. The small script is easier to review and repeat, but it still needs tests and human checks.
Before you start
You need:
- Codex CLI installed and signed in, in a disposable project folder.
- Python available locally.
- A Git checkpoint or a copy of the folder before asking for changes. The Codex documentation recommends checkpoints so you can revert work.
- No credentials, customer data, or production folders in the exercise.
Create sales.csv:
sale_id,week,product_code,region,quantity,amount
S-101,2026-W40,P-10,West,3,300
S-102,2026-W40,P-11,,2,180
S-103,2026-W40,P-99,East,-1,-50
S-104,2026-W41,P-10,West,4,400
Create products.csv:
product_code,product_name
P-10,Desk lamp
P-11,Notebook
The illustrative checks are: S-102 has a missing region, S-103 has a negative quantity and amount, and S-103 also has an unknown product code. S-101 is the only complete row in week 2026-W40. These are checks against the sample, not generated results.
Three steps
1. Ask for a plan, not a rewrite
From the project folder, run:
codex
Paste this request:
Plan a small local Python utility for sales.csv and products.csv.
Requirements:
- Read both CSV files without changing them.
- Accept a week such as 2026-W40 as a command-line argument.
- Write a new report file such as report-2026-W40.csv.
- Include every sales row for the requested week.
- Flag missing region, quantity less than or equal to zero, amount less than zero, and product codes missing from products.csv.
- Keep the original sale_id and source values in the report.
- Add tests for one complete row, a missing region, a negative quantity, and an unknown product code.
- Do not use the network, credentials, external services, or destructive file operations.
- Do not create files or run commands yet. Return the proposed files, report columns, tests, and acceptance checks.
Review the plan. It should name the input files, output path, validation rules, and tests before it writes code.
2. Request a bounded implementation
After reviewing the plan, paste:
Implement only the approved local utility and its tests.
Before writing, show the files you intend to create. Keep the patch limited to this folder. Use the Python standard library unless a dependency is necessary and explicitly justified. Do not modify sales.csv or products.csv. Do not run network commands. Add a dry-run option that prints the output path and row count before writing. Then show the diff and the exact test command. Stop for review before running the utility against any real data.
Inspect the diff yourself. Confirm that the script opens the input files for reading, creates a new output path, and does not include an upload, connector, or credential step.
3. Run the sample and check the artifact
Only after reviewing the diff, ask Codex to run the tests and the fictional sample:
Run the tests. Then run the utility for week 2026-W40 in dry-run mode and show the proposed report rows without modifying the input files. Check the report against these acceptance rules:
1. S-101 is complete.
2. S-102 is flagged for a missing region.
3. S-103 is flagged for negative quantity and amount.
4. S-103 is flagged for an unknown product code.
5. S-104 is excluded because it belongs to week 2026-W41.
6. sales.csv and products.csv remain byte-for-byte unchanged.
Report the command output and any failed check. Do not claim success if a check was not observed.
If the run passes, open the report as a separate artifact and compare its values with the source rows. A passing test suite does not prove that the business rules are correct.
Illustrative report shape
sale_id,week,product_code,region,quantity,amount,flags
S-101,2026-W40,P-10,West,3,300,
S-102,2026-W40,P-11,,2,180,missing_region
S-103,2026-W40,P-99,East,-1,-50,non_positive_quantity;negative_amount;unknown_product_code
This is an editor-written example. It is not output from Codex or Python.
What happened when I ran it
On 30 October 2026 I ran the three prompts from the steps above, in order, once, in a scratch Git folder with the fictional sales.csv, products.csv and one checkpoint commit. I used Codex CLI 0.164.0 non-interactively: codex exec -s workspace-write for step 1, then codex exec resume --last for steps 2 and 3. Every step exited normally.
Step 1, the plan. Codex proposed report.py and test_report.py, the Python standard library only, and a refusal to overwrite an existing report. It created no files, as asked. It also assumed the sales file has a date column and labelled that a low-confidence assumption. The sample has a week column instead. The implementation step used the real week column, so nothing broke, but this is why the plan review matters.
Step 2, the implementation. Codex wrote two files and nothing else: git status listed only report.py and test_report.py. It had already written them when it stopped for review, so the diff review is a check of a finished edit. It wrote three test functions, covering flags and source values, the dry run and an existing report, and invalid values and an empty week.
Step 3, the run. Codex ran the tests (3 passed) and a dry run for 2026-W40, which printed the output path and Rows: 3 and wrote no report. It then reported all six acceptance rules as met. I did not take that on trust. On a copy of the folder I ran the tests, the dry run and a real write myself. The report matched, and a second run refused to overwrite it and exited with an error. sales.csv and products.csv had identical SHA-256 hashes before and after.
The real report, as written by Codex’s script:
sale_id,week,product_code,region,quantity,amount,validation_flags
S-101,2026-W40,P-10,West,3,300,
S-102,2026-W40,P-11,,2,180,missing_region
S-103,2026-W40,P-99,East,-1,-50,quantity_not_positive;negative_amount;unknown_product_code
It differs from the illustrative shape above in two names: the last column is validation_flags, not flags, and the quantity flag is quantity_not_positive, not non_positive_quantity. Neither name was in the prompts, so a different run could choose others. Decide the names you want before you ask.
This was one run on my own Codex installation, which loads my personal configuration, so a clean installation or another model may behave differently. It shows that the three-step process works on this sample. It does not show that the flag rules suit your sales data.
Acceptance checks
The lesson is complete when:
- The proposed patch contains only the utility and its tests.
- Tests cover the four required cases.
- The requested week is filtered without changing the source rows.
- The report preserves original values and names each flag.
- The dry-run shows what would be written before writing it.
- The input files remain unchanged after the sample run.
- A reviewer can reproduce the commands from the project folder.
If something goes wrong
- The script overwrites the CSV: stop, restore the checkpoint, and require a new output path before running anything.
- S-103 is treated as valid: inspect the comparison operators and add a direct test for negative quantity and amount.
- S-104 appears in the report: check whether the week argument is being ignored or compared as a number instead of a string.
- The product check passes every row: verify that the script reads products.csv and compares product codes, not product names.
- Codex wants an external package or network access: reject the step for this exercise and ask for a standard-library implementation.
Limits and safe use
A local script can repeat a rule consistently while still encoding the wrong rule. Have the process owner approve the flags, date format, currency handling, and output destination before using real sales data. Do not connect this exercise to a CRM, accounting system, or automatic email step.
Evidence label
Documentation-based builder guide with fictional CSV files and an illustrative report shape, plus one recorded Codex run on 30 October 2026 (see “What happened when I ran it”). No production use or measured benefit is claimed.