Use this when automation reads or writes CSV files.
CSV
CSV (comma-separated values) stores tabular data as text rows, easy to export from spreadsheets and import into scripts with Import-Csv or Python's csv module, but with no data types or nesting.
1. CSV: simple tabular data.
2. No standard types — validate columns.
3. Quoting for commas/newlines.
4. Encoding issues (UTF-8 BOM, Windows-1252).
5. Prefer JSON/YAML for nested data.
CSV → parser → rows → validation
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Effective-state and workload closure Verify boundary
Local intent: CSV reference under Data Formats in the Automation Domain.
Step 2 Verification path Verify boundary
The primary procedure is: Parse a fixture containing commas, quotes, CRLF/newlines and empty fields with the production parser settings; serialize it again and compare field values and column count. Exercise failure-oriented cases such as embedded commas/newlines, doubled quotes, trailing empty columns, BOM/encoding drift, duplicate headers and rows with unexpected field counts so the test covers failure cases, not only the happy path.
Step 3 Branching troubleshooting Narrow the fault
Path: Automation → Data Formats → CSV. Local intent: CSV reference under Data Formats in the Automation Domain.
Step 4 Where it fails Narrow the fault
Failure analysis for Data Formats → CSV should follow the path through the components: producer serialization → transport/storage → byte decoding → CSV lexical parsing → header/schema mapping → typed consumer validation. Tests should include edge cases such as embedded commas/newlines, doubled quotes, trailing empty columns, BOM/encoding drift, duplicate headers and rows with unexpected field counts. Recovery should preserve the original bytes and parser settings, correct the dialect/schema mismatch instead of hand-editing rows, then reparse the same fixture and compare typed records.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
Subtopics
Go one level deeper into this subject.
CSV rows are records, one per line after the header. Validate each row in automation and report bad ones by line number instead of failing the whole import silently.
Subtopic ColumnsCSV columns are the fields in each row, usually named in a header line.
Subtopic DelimitersCSV delimiters separate fields, normally a comma, but semicolons are common in European Excel exports and tabs in TSV.
Subtopic ParsingParse CSV with a real parser, such as Import-Csv -Delimiter or Python's csv module, not by splitting on commas, so quoted fields, embedded newlines and encodings like UTF-8 with BOM are handled.
- No data types or nesting.
- Delimiters vary.
- Use a real parser.
head -3 file.csv— header and samplecsvlint / python csv check— validityfile file.csv— encoding
ReferenceWhy it matters1 section · depth on demand
Internals and state
Local intent: CSV reference under Data Formats in the Automation Domain.
ReferenceImportant terms & boundaries2 sections · depth on demand
Mechanics
CSV in Data Formats is owned at runtime by the CSV producer/parser pair interpreting records, fields, quoting and line boundaries. The durable intent is documented dialect contract: delimiter, quote character, header presence, encoding, newline policy and null/empty conventions. Reliable automation must carry stable identity across the path: file/object version, header schema and record position or business key. The consumer-visible target is typed records consumed by automation rather than the raw textual lines themselves. The key invariants are consistent field count, correct escaping of delimiters/quotes/newlines, deterministic header mapping and explicit handling of empty versus absent values.
In depth
CSV (comma-separated values) is a plain-text table format: one record per line, fields separated by a delimiter, usually with a header row. It is popular for exchanging inventories and bulk data with spreadsheets, but has no types, nesting or formal standard beyond RFC 4180.
| Pitfall | Handling |
|---|---|
| Commas or newlines inside fields | Quote fields ("Oslo, HQ") |
| Delimiter varies by locale | Detect or set (; in many European Excel exports) |
| Excel BOM in first header | Read with utf-8-sig |
| Everything is a string | Convert and validate types explicitly |
| Leading zeros/long numbers mangled by Excel | Keep IDs as text |
import csv
with open("devices.csv", newline="", encoding="utf-8-sig") as f:
rows = list(csv.DictReader(f))
For nested or typed data, prefer JSON or YAML.
ReferenceConfiguration & state1 section · depth on demand
Lifecycle
Store and review documented dialect contract: delimiter, quote character, header presence, encoding, newline policy and null/empty conventions; pin or at least record implementation/model versions and keep environment-specific identity outside reusable logic where possible. The stable identity contract is file/object version, header schema and record position or business key.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Data Formats > CSV. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://www.rfc-editor.org/rfc/rfc4180.html · confidence 94%Quick lookup tables
Data Formats → CSV · operational reference
Context-specific ownership, verification, output and failure-boundary lookup for Data Formats → CSV.
| Layer | Data Formats → CSV operational reference |
|---|---|
| Runtime/ownership | CSV interchange and automation parsers · the CSV producer/parser pair interpreting records, fields, quoting and line boundaries |
| Persistent intent | documented dialect contract: delimiter, quote character, header presence, encoding, newline policy and null/empty conventions |
| Verification | Parse a fixture containing commas, quotes, CRLF/newlines and empty fields with the production parser settings; serialize it again and compare field values and column count. |
| Expected interpretation | Each logical record and field round-trips without delimiter/quote corruption, headers map deterministically, and malformed rows are rejected or surfaced rather than silently shifted. |
| Recovery boundary | preserve the original bytes and parser settings, correct the dialect/schema mismatch instead of hand-editing rows, then reparse the same fixture and compare typed records |
Deep reference
Healthy vs suspicious evidence
Output interpretation
At minimum retain file/version identifier, encoding, delimiter/quote settings, header list, row number, parsed field count, rejected-row reason and typed validation result. The useful output makes ambiguity visible, links to the target identity from file/object version, header schema and record position or business key, and provides enough context to safely decide whether a retry is permitted.