Fixed-width exports, quote-mangled CSVs, inconsistently nested JSON, and yet another paginated REST API: ingestion code is high-volume, low-glory work that AI assistants handle exceptionally well from a few sample records or a pasted API doc.
The trick is adversarial testing — the assistant writes the parser, and then you make it write the test cases designed to break its own parser.
Reach for this when a new feed arrives in a format that needs custom parsing, or when you need connector scaffolding (pagination, rate limits, retries) for an API with published docs. It is the fastest AI win in daily ingestion work because the input is small, self-contained, and easy to verify.
Triggers:
Curate representative samples. Take 10–20 real records including the ugly ones — the row with a quote inside a quoted field, the record with the missing optional column, a non-ASCII name. Mask any sensitive values but preserve structure exactly (do not "clean up" whitespace).
Prompt with samples plus explicit failure behavior.
Write a Python function parse_settlement_line(line: str) -> dict for the
fixed-width settlement file sampled below.
Layout (from the vendor spec):
- cols 1-10: account_id (right-padded)
- cols 11-18: settle_date YYYYMMDD
- cols 19-30: amount, implied 2 decimals, leading zeros, "-" suffix = negative
- cols 31-33: currency ISO-4217
Rules:
- Return Decimal for amount, datetime.date for settle_date.
- On any malformed field, raise ParseError with the field name and raw
value — never guess, never silently skip, never coerce.
- No dependencies outside the standard library + decimal.
Sample lines:
[paste 10-20 raw lines]
Make it attack its own code. In the same conversation:
Now write pytest cases designed to BREAK this parser: truncated lines,
amount overflow, "-" suffix handling, non-numeric dates, empty account_id,
a line with trailing whitespace, and a Unicode character in the account
field. Include the expected behavior for each per the rules above.
Run the tests. Failures here are the review — fix the parser (in-conversation, scoped) until they pass.
Verify against volume, not just samples. Run the parser across a full historical file and assert the reconciliation invariants inline:
-- after loading parsed output to a staging table
SELECT COUNT(*) AS parsed_rows,
SUM(amount) AS total_amount
FROM stg_settlements;
-- compare parsed_rows to `wc -l` of the file and total_amount
-- to the control-total trailer record the vendor provides
For API connectors, paste the docs — not a memory of them. Give the assistant the actual pagination and rate-limit sections from the API documentation and require: cursor-based pagination handled to exhaustion, Retry-After honored on 429s, exponential backoff with jitter, and idempotent checkpointing so a rerun resumes rather than duplicates. Ask it to enumerate which doc section justifies each behavior — an unjustifiable behavior is a hallucination.
Dry-run the connector against a sandbox or low-volume window and check the checkpoint file survives a mid-run kill and resume without duplicating records.
"Never guess, never silently skip" belongs in every parser prompt. The default failure mode of AI-written parsers is heroic coercion — bad data flowing through as plausible values instead of loud errors.
float for currency. Demand Decimal in the prompt and grep the output for float( before running.Vendor file layouts and API docs are usually not sensitive, but sample records almost always are. On client work, generate the parser from the layout spec plus synthetic sample lines you construct to match the spec (or client samples with every value replaced, structure intact), via approved-tenancy Bedrock/Azure OpenAI or a local Ollama model. Run the adversarial tests and full-file control-total verification inside the client environment on real data — the parser is proven where the data lives, while the prompt never contains a real record.