Tencent/WeKnora · error

csv conversion failed: %w

Error message

csv conversion failed: %w

What it means

The built-in document converter converts CSV files to Markdown tables via csvToMarkdown. This error wraps any failure in that conversion — most commonly malformed CSV (ragged rows, bad quoting, wrong delimiter) that the Go encoding/csv parser rejects.

Source

Thrown at internal/infrastructure/docparser/builtin_converter.go:64

// bypassing the Python docreader service.
type SimpleFormatReader struct{}

// Read reads simple format files and returns markdown.
func (b *SimpleFormatReader) Read(_ context.Context, req *types.ReadRequest) (*types.ReadResult, error) {
	ft := strings.ToLower(strings.TrimPrefix(req.FileType, "."))
	if ft == "" {
		ft = strings.TrimPrefix(strings.ToLower(filepath.Ext(req.FileName)), ".")
	}

	switch {
	case ft == "md" || ft == "markdown":
		return &types.ReadResult{MarkdownContent: string(req.FileContent)}, nil
	case ft == "txt" || ft == "text":
		return &types.ReadResult{MarkdownContent: string(req.FileContent)}, nil
	case ft == "csv":
		md, err := csvToMarkdown(req.FileContent)
		if err != nil {
			return nil, fmt.Errorf("csv conversion failed: %w", err)
		}
		return &types.ReadResult{MarkdownContent: md}, nil
	case ft == "json":
		md, err := jsonToMarkdown(req.FileContent)
		if err != nil {
			return nil, fmt.Errorf("json conversion failed: %w", err)
		}
		return &types.ReadResult{MarkdownContent: md}, nil
	case imageFormats[ft]:
		return imageToResult(req.FileName, req.FileContent), nil
	case audioFormats[ft]:
		return audioToResult(req.FileName, req.FileContent), nil
	default:
		return nil, fmt.Errorf("unsupported simple format: %s", ft)
	}
}

// imageToResult wraps a standalone image as a markdown image reference with

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Open the file and fix the malformed CSV row/column the underlying error points to.
  2. Pre-convert the file to well-formed UTF-8 comma-separated CSV (or resave from Excel as 'CSV UTF-8').
  3. Convert the delimiter to a comma (or extend csvToMarkdown to sniff delimiters).
  4. If the file is genuinely tab-separated, rename to .tsv and route through a TSV handler.

Example fix

// before
# data.csv with semicolons
ame;age
Bob;3
// after
# re-export as comma-separated UTF-8
name,age
Bob,3
Defensive patterns

Strategy: validation

Validate before calling

r := csv.NewReader(bytes.NewReader(req.FileContent))
r.FieldsPerRecord = -1
if _, err := r.ReadAll(); err != nil {
    return fmt.Errorf("not valid CSV: %w", err)
}

Type guard

func looksLikeCSV(data []byte) bool {
    r := csv.NewReader(bytes.NewReader(data)); r.FieldsPerRecord = -1
    rows, err := r.ReadAll(); return err == nil && len(rows) > 0
}

Try / catch

res, err := reader.Read(ctx, req)
if err != nil && strings.Contains(err.Error(), "csv conversion failed") {
    var csvErr *csv.ParseError
    if errors.As(err, &csvErr) { log.Printf("bad CSV at line %d", csvErr.Line) }
}

Prevention

When it happens

Trigger: Calling Read with a request whose detected file type is "csv" and where csvToMarkdown fails: unterminated quotes, invalid rune in quote, or inconsistent field counts per row.

Common situations: Users upload Excel-exported CSVs with semicolon or tab delimiters assumed to be comma; embedded unescaped quotes/newlines; files with a BOM or mixed encodings (GBK/latin-1) breaking the parser; files renamed .csv but actually TSV.

Related errors


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/4ea32cf139e7ea2d. Report an issue: GitHub.