zed-industries/zed · error

Failed to parse example on {}:{} {error}

Error message

Failed to parse example on {}:{}
{error}

What it means

For .jsonl inputs every line must be a complete Example object. The loader enumerates lines and, on the first that fails serde parsing, panics with the file, the 1-based line number, and the serde error. Blank lines fail too, since every line is passed to from_str unchanged.

Source

Thrown at crates/edit_prediction_cli/src/example.rs:257

        match ext.as_ref() {
            "json" => {
                let mut example =
                    serde_json::from_str::<Example>(&content).unwrap_or_else(|error| {
                        panic!("Failed to parse example file: {}\n{error}", path.display())
                    });
                if example.spec.name.is_empty() {
                    example.spec.name = filename;
                }
                examples.push(example);
            }
            "jsonl" => examples.extend(
                content
                    .lines()
                    .enumerate()
                    .map(|(line_ix, line)| {
                        let mut example =
                            serde_json::from_str::<Example>(line).unwrap_or_else(|error| {
                                panic!(
                                    "Failed to parse example on {}:{}\n{error}",
                                    path.display(),
                                    line_ix + 1
                                )
                            });
                        if example.spec.name.is_empty() {
                            example.spec.name = format!("{filename}-{line_ix}")
                        }
                        example
                    })
                    .collect::<Vec<Example>>(),
            ),
            "md" => {
                let mut example = parse_markdown_example(&content).unwrap();
                if example.spec.name.is_empty() {
                    example.spec.name = filename;
                }
                examples.push(example);

View on GitHub (pinned to f4178619ac)

Solutions

  1. Go to the exact file:line from the panic and fix or delete that record
  2. Strip blank lines: grep -v '^$' in.jsonl > clean.jsonl
  3. Find all bad lines at once: jq -c '.' < in.jsonl > /dev/null — it reports each failing line number
  4. Regenerate the JSONL from its source instead of hand-editing

Example fix

# before — examples.jsonl contains a blank line
# panic: Failed to parse example on examples.jsonl:2

# after
grep -v '^$' examples.jsonl > examples.clean.jsonl
edit-prediction-cli eval examples.clean.jsonl
Defensive patterns

Strategy: validation

Validate before calling

bad_lines = [
    ix + 1
    for ix, line in enumerate(content.splitlines())
    if not line.strip() or serde_json::from_str::<Example>(line).is_err()
]
assert not bad_lines, f"unparseable lines: {bad_lines}"

Prevention

When it happens

Trigger: A blank line inside the file; a truncated final line from an interrupted write; one record missing required fields; pretty-printed multi-line JSON saved with a .jsonl extension.

Common situations: Appending records with stray trailing newlines; partially downloaded datasets; hand-merging files with different schemas; editors auto-adding a final newline creating an empty record expectation.

Understand the failure class

Related errors


AI-assisted analysis of zed-industries/zed@f4178619ac (2026-08-20). Data as JSON: /api/errors/153be5c60f08cc1f. Report an issue: GitHub.