# Lead Capture — CSV Import

**Document Version:** 1.0.0 (Phase 11)

---

## 1. Overview

The CSV Import engine allows importing batches of leads (up to 2,000 rows per batch, max 5MB file size) with interactive column mapping, formula injection protection, bounded processing, and per-row error tracking.

---

## 2. Import Workflow

```
1. Upload File (.csv, .txt)
       ↓
2. Auto-Detect Columns & Preview First 5 Rows
       ↓
3. Interactive Field Mapping
       ↓
4. Bounded Ingestion Loop via LeadIngestionService
       ↓
5. Detailed Results Summary (Imported, Skipped, Duplicates, Errors)
```

---

## 3. Security & Safety Controls

1. **Formula Injection Sanitization:** Any cell starting with `=`, `+`, `-`, `@`, `\t`, or `\r` is escaped with a leading single quote (`'`).
2. **File Validation:** Strict extension (`.csv`, `.txt`) and MIME type checks. Max size 5MB.
3. **Batch Boundary:** Hard limit of 2,000 rows per import batch to prevent memory exhaustion.
4. **Temporary File Isolation:** Uploaded files stored in private local app storage and unlinked immediately after processing.
5. **Partial Failure Tolerance:** A single invalid row does not fail the entire batch. Valid rows succeed and invalid rows are logged in `import_batches.error_log`.
