Skip to content

Work through a large CSV file

Who this is for: people who write workflows that process an export, such as all orders of the day or all users of a system, record by record.

Before you start: you need the Edit workflows permission (edit_workflow) to change a workflow.

A for-each step over a list handles at most 1,000 items, and the whole list sits in the step’s output. For a bigger CSV file, let the step read the file itself with for_each_record. The step runs once per record, 1,000 records at a time, and only counts end up in its output.

First get the file into the run, for example from an SFTP folder with files.download. Then point for_each_record at it:

steps:
- id: download
name: Download the order export
uses: platform/files.download@v1
connections: { store: partner-sftp }
with:
path: exports/orders.csv
- id: post
name: Post each order to the ERP
uses: platform/http.request@v1
connections: { api: erp }
retry: { attempts: 3, on: [429, 5xx, timeout, network] }
strategy:
for_each_record:
csv: ${{ steps.download.outputs.artifact }}
delimiter: ";"
max_parallel: 5
quarantine: true
with:
method: POST
url: /v1/orders
json: ${{ each.item }}
- id: report
name: Email the totals
uses: platform/email.send@v1
with:
to: [orders@example.com]
subject: "Orders posted: ${{ steps.post.outputs.succeeded }} of ${{ steps.post.outputs.count }}"
text: "${{ steps.post.outputs.quarantined }} orders were set aside. Open the run to see them."
  • each.item is one record. With a header row (the default), it is an object keyed by the column names, such as {"order": "1042", "amount": "19.90"}. Every value is text. Set has_header: false to get each record as a list of its fields instead.
  • each.index is the record’s position in the file, from 0. The header row is not counted.
  • The file can be any CSV file of the run: one a step downloaded, built or unpacked, or ${{ artifacts.<name> }}.

See the workflow format for every key.

The output is counts, not the records’ results: count (records in the file), succeeded, failed and quarantined. Use them in later steps, as the email above does. Each record’s own result is in the run’s step details.

If a later step needs results of the records together, write them to a file record by record, or use for_each on a smaller list instead.

  • At most 100,000 records, 1,000 columns and 50 MB per file. A bigger file fails the step with format_error or artifact_too_large before any record runs. Split it first, for example by date.
  • The whole file is checked before the first record runs. A record with the wrong number of fields, a quote that is never closed, or text that is not UTF-8 fails the step without changing anything. The message gives the record’s position, never its values.
  • The file is read in batches of 1,000 records. max_parallel records run at the same time inside a batch, and the next batch starts when the previous one is done.
  • One record keeps failing. With quarantine: true, the record is set aside after its retries and the rest go on. The run ends as failed with items_quarantined. Fix the cause and replay the quarantined items: only those records run again, read from the same file.
  • Without quarantine, the first failed record stops the step (unless you set fail_fast: false), and later batches don’t start.
  • The run was interrupted, for example by a platform restart. When it continues, records that are done are not run again. Liitora keeps a fingerprint of the file, and if the file changed in between, the step stops with item_changed instead of guessing which records are new. Start a new run to process the current file.

Liitora counts the records a step works through, one batch at a time once the batch is done. You see the total under Records from CSV files on the Usage page. A record that is retried or picked up again after an interruption counts once. Records are counted, not charged. Dry runs are not counted.

A workflow with runs-on: self-hosted/... can’t use for_each_record yet, because runners can’t read the run’s files. Its runs fail with runner_unsupported before anything runs.

In a workflow test, give the file under given.artifacts, as if an earlier step had stored it. This works when the step reads the file by its name, for example csv: ${{ artifacts['orders.csv'] }}. A test for the workflow above also needs the download step stubbed.

{
"name": "Every order is posted",
"given": {
"artifacts": {
"orders.csv": { "content_type": "text/csv", "text": "order;amount\n1042;19.90\n1043;5.00\n" }
}
},
"expect": {
"outcome": "success",
"payload": [{ "path": "$.steps.post.outputs.count", "equals": 2 }]
}
}