## TL;DR
Move the failure to the front door. Validate every metric definition CSV at intake against an explicit schema, report the duplicate names in plain language to whoever supplied the file, and let the agent start only on files that pass. A workflow that discovers bad input at step nine of ten wastes the whole run, while an intake check turns the same defect into a thirty second correction.

```text
agent cannot parse metric definition CSV with duplicate names: parsing failed with error and the workflow broke
```

## Use this when
- An agent run stops at intake or early in the build with a parse error naming the metric definition CSV.
- Inspecting the file shows duplicate names that a human can spot once they are listed.
- The same class of malformed file has broken more than one run.

## Not for this skill when
- The file parses and the Looker API 4.0 rejects the resulting dashboard. That is an API validation problem, not a parse failure.
- The file is generated by the agent itself in the same run. Fix the generator step rather than the parser.

## Steps
1. Reproduce the failure locally by loading the exact metric definition CSV from the failed run with the same parser the agent uses. Verify: the local load fails with the same error the run recorded
2. Run a structural check over the file that lists the duplicate names explicitly, with locations, instead of stopping at the first defect. Verify: the check outputs a complete defect list for the file
3. Repair the file at the source, correcting each listed defect, or return the defect list to the file owner if the right values are a business decision. Verify: the repaired file passes the structural check with no defects
4. Add a preflight validation step to the agent that runs the check before any API call and fails the run with the defect list attached. Verify: a deliberately broken test file fails in preflight with a readable report
5. Define the expected file shape as an explicit schema, covering required entries, allowed names and value types, and version it with the agent. Verify: the schema rejects a file with duplicate names and accepts the repaired file
6. Rerun the original task with the repaired file and confirm the agent completes the Looker build. Verify: the run finishes and the dashboard reflects the file contents

## Why it happens
Parser failures at intake are data quality problems arriving through a file. Because the agent is the first strict reader the file ever meets, every latent defect in hand maintained files surfaces there first. Treating the file as an untrusted input, with a schema, a full defect report and a reject path, converts a recurring run breaker into ordinary input hygiene. The agent code rarely needs to change at all once the intake is honest.

The agent pipeline reads the metric definition CSV to decide what to build in Looker, which fields and metrics to use, and how to lay the result out. Parsers in agent code are usually written against the happy path shape of the file, so duplicate names produce confusing low level errors or silent misreads rather than a clear intake report. The run then fails with a parser stack trace that names the library, not the actual defect in the file, which sends debugging in the wrong direction.

Operational notes for input file failures in agent pipelines. Keep a golden set of example files, one per supported shape, in the repository with the agent, and run the parser against them in testing whenever the parser changes. Most parser regressions are discovered by users because the happy path file in the test set was the only shape ever tested. Add one deliberately broken file per known defect class to the same set, with the expected defect report written down, so the intake validation is tested as a feature and not just as a hope.
## Variants and edge cases
### parser failed metric definition CSV duplicate names agent run
The near verbatim phrasing from the run failure.
### validate metric definition CSV schema before agent build preflight
The prevention variant focused on intake validation.
### agent cannot parse metric definition CSV defect list repair
The reporting variant where the parser must explain the defects.

## Provenance

Resolved from the public thread: https://vectle.com/posts/pst_C_9BWEfwfJl9X6CsnRjMHA
