Coding
AI Prompt for Data Parser Functions
Generate robust data parsers with this AI prompt: handles messy CSV/JSON, validates rows, reports bad data, and never crashes on real-world files.
The prompt
Role: You are a data engineer who writes parsers that survive real-world messy data. Context: Language: [LANGUAGE]. Input format: [FORMAT: CSV / JSON / fixed-width / log lines / etc.]. Messiness to expect: [MESSINESS, e.g. quoted commas, missing fields, blank lines, mixed encodings]. Desired output: [OUTPUT_SHAPE]. Bad-data policy: [STRICTNESS: fail fast / skip and log / collect errors]. Task: 1) Write the parser using [LANGUAGE]'s standard parsing libraries (not hand-rolled string splitting). 2) Handle every listed messiness case explicitly. 3) Implement the bad-data policy: invalid rows are [STRICTNESS] with clear diagnostics (row number + reason). 4) Provide sample input demonstrating the messy cases and the parsed output. Format: Parser code first, then the sample input/output demonstration. Ask the AI to include a data-quality report: counts of skipped rows grouped by failure reason, emitted at the end of the run. Silent skips hide data problems; a summary makes them visible and actionable. Constraints: Never crash on malformed input — diagnose it per the policy. Stream large inputs instead of loading everything into memory; note the approach.
Variables to fill in
Replace each [variable] in the prompt with your own details:
[LANGUAGE] [FORMAT] [MESSINESS] [OUTPUT_SHAPE] [STRICTNESS]
Example input
LANGUAGE=Python, FORMAT=CSV with headers, messy: quoted fields with commas, occasional blank lines, OUTPUT=list of dicts, STRICTNESS=skip bad rows but log them
How to use this prompt
Describe the messiness honestly — quoted commas, blank lines, and encoding issues are where parsers die. Choose strictness: fail fast for pipelines, skip-and-log for imports.
Tips for the best results
- Test with your ugliest real file, not a clean sample — reality is messier.
- Ask for a row-error report format your team can actually act on.
- For huge files, confirm the streaming approach and test with a 1GB sample.
Frequently asked questions
Should I write my own parser?
Always use the standard library parser (csv, json) — the prompt enforces this because hand-rolled parsers break on quoted fields.
What if my file is too big to fit in memory?
Mention the size in the prompt — it will use streaming line-by-line processing. Always confirm the streaming approach before running on multi-gigabyte files.