Builder tools
Use Codex to Build a Small CSV Report with Tests and a Dry Run
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, implementation, and output in this guide are illustrative. No Codex run is claimed.
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.
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. No Codex execution, test output, production use, or measured benefit is claimed.