baml.csv.ReaderOptions

Options for CSV readers. All fields are optional; `null` means default.

Reference version

Signature

class baml.csv.ReaderOptions

Options for CSV readers. All fields are optional; null means default.

delimiter, quote, escape, and comment must be single ASCII bytes (never CR or LF) and mutually distinct; violations throw Error { kind: Options } at construction, as do negative skip_lines, max_skipped, or limit. Validating up front means a misconfiguration surfaces from reader / open, not a million records in.

Source:<builtin>/baml/ns_csv/csv.bamlbytes 36796324

Fields

delimiter

string | null

Field separator. Exactly one ASCII byte. Default "," ("\t" for TSV).

quote

string | null

Quote character. Exactly one ASCII byte. Default "\"".

quoting

bool | null

false treats quote bytes as ordinary data. Default true.

escape

string | null

Escape byte for quotes. null (default) means RFC 4180 "" doubling; setting it switches to escape-character dialects ("\\" for MySQL-style dumps).

has_header

bool | null

First record is the header. Default true.

headers

string[] | null

Supply (has_header = false) or replace (has_header = true; the file's header row is consumed) column names.

comment

string | null

Records whose first byte (outside quotes) matches are skipped. Off by default — # is valid data.

trim

"none" | "headers" | "fields" | "all" | null

Strip leading/trailing ASCII space and tab from header and/or unquoted field values. Default "none".

skip_lines

int | null

Raw lines dropped before parsing begins (preamble junk, Excel sep=; lines, a Markdown code fence). Default 0.

skip_blank_records

bool | null

Drop blank records. Default true.

ragged

"strict" | "pad" | "truncate" | null

Ragged-record policy. "strict" (default): width mismatch throws FieldCount. "pad": short records padded with empty cells (long ones still throw). "truncate": long records cut to the expected width (short ones still throw).

null_values

string[] | null

Unquoted cell texts (after trim) treated as null cells. Default [].

encoding

"utf8" | "utf8-lossy" | null

"utf8" (default) throws Encoding on invalid bytes; "utf8-lossy" substitutes U+FFFD.

bom

"strip" | "keep" | null

A leading UTF-8 BOM is stripped by default so it never corrupts the first header name.

on_error

"throw" | "skip" | null

Per-record error policy. "throw" (default): next() throws a Error for a malformed record and the reader resumes at the next record. "skip": record-scoped errors are counted and skipped.

on_skip

((baml.csv.Error) -> null throws never) | null

Observer invoked with each skipped record's Error when on_error = "skip". Constant-memory alternative to skipped().

max_skipped

int | null

How many skipped Error values skipped() retains. Default 1000. 0 disables retention. skipped_count() stays exact regardless.

limit

int | null

Stop after this many data records. Default unlimited.

Implementations

baml.Concrete for T

Source:<builtin>/baml/core.bamlbytes 747779