Specifying input and output formats, and checking generated solutions
Specify data formats exactly and check a generated solution with test cases.
Precise data formats
Data tasks fail on small details. Specify:
- Structure — CSV, table, JSON, list; column names and order.
- Types and units — "price in US dollars as a number with 2 decimals", "dates as YYYY-MM-DD".
- Missing values — "write null", "leave blank" or "write 'unknown'".
- Sorting and duplicates — "sorted by date ascending; remove exact duplicate rows".
- Encoding and separators where relevant — "comma-separated, UTF-8, header row".
Show a sample of input and the exact expected output for it:
Input row: 03/07/2024, "Desk lamp", 2, 19.5
Output row: 2024-07-03,Desk lamp,2,19.50
Note: input dates are day/month/year.
That last note matters: "03/07/2024" is 3 July in the UK and March 7 in the US. Ambiguous formats are a classic source of silent errors.
Ask for tests, not only code
Prompt for checks alongside the solution:
- "Give 5 test cases, including an empty input, a row with missing price and a duplicate row, with the expected output for each."
- "Write a small function that checks the output has the right columns and no negative quantities."
Then run the tests yourself. A model's claim that "this code passes all tests" is not evidence; running the tests is.
Checking a generated solution
- Read it. Do you understand what each part does? If not, ask for an explanation first.
- Run it on a copy of the data or on fake data — never first on the only copy.
- Test edge cases — empty input, very large values, unusual characters, missing fields.
- Check a sample by hand — recalculate two or three results yourself.
- Check dependencies — do the functions and libraries exist in your version? Are they from trustworthy sources?
- Consider side effects — does it delete, overwrite, send or publish anything?
Calculations
Language models can make arithmetic mistakes, especially over many steps. For numbers that matter, ask for the method or a formula, then compute with a calculator, spreadsheet or code — and spot-check the result.
Explaining data, not inventing it
When you ask for analysis ("What trends do you see in this table?"), constrain it: "Base every statement on the data provided. Give the specific numbers that support each trend. If the data is insufficient to conclude something, say so." Then verify the numbers it quotes.
Practice exercise
Using fake data (5–10 rows):
- Write a prompt that specifies input and output formats exactly, including dates, units and missing values.
- Ask for at least four test cases including edge cases.
- Check two outputs by hand and record whether they were correct, and anything you had to fix.