When every model returns an error (e.g. all API keys are missing),
export() crashes with an IndexError instead of writing an empty file
or giving a clear error message.
How to reproduce
Set no API keys, then run:
assayer run "hello" --models gpt-4o --output results.csv
All results will have error set. The exporter then hits:
# exporter.py:21
writer = csv.DictWriter(f, fieldnames=list(records[0].keys()))
# ^^^ IndexError: list index out of range
What needs to happen
The CSV field names are always the same — they come from ModelResult.
Hardcode them instead of deriving from the first record:
_FIELDS = ["model", "output", "tokens_input", "tokens_output",
"latency_seconds", "cost_usd", "error"]
Then use _FIELDS in both the CSV writer and guard against empty input:
if not records:
return # or raise a friendly click.echo message
Files to touch
assayer/exporter.py — replace records[0].keys() with a fixed field list,
add an early return for empty input
How to test
Add a test in tests/test_exporter.py:
def test_export_csv_empty_results_does_not_crash(tmp_path):
path = tmp_path / "results.csv"
export([], str(path)) # should not raise
When every model returns an error (e.g. all API keys are missing),
export()crashes with anIndexErrorinstead of writing an empty fileor giving a clear error message.
How to reproduce
Set no API keys, then run:
All results will have
errorset. The exporter then hits:What needs to happen
The CSV field names are always the same — they come from
ModelResult.Hardcode them instead of deriving from the first record:
Then use
_FIELDSin both the CSV writer and guard against empty input:Files to touch
assayer/exporter.py— replacerecords[0].keys()with a fixed field list,add an early return for empty input
How to test
Add a test in
tests/test_exporter.py: