An LLM data pipeline is a data engineering system that prepares training data for large language models. It crawls web sources, filters low-quality content, removes PII, deduplicates near-identical documents, tokenizes text into integer sequences, and packages datasets in formats like Parquet or Arrow for training jobs. Unlike RAG (which runs at inference time), an LLM pipeline runs offline and produces static datasets — it is a throughput problem at billion-token scale. Learn it hands-on at /learn/llm-pipeline or build one at /projects/llm-ingestion-pipeline.
What is an LLM Pipeline?
Training a large language model requires trillions of tokens of high-quality text. Assembling that dataset is a data engineering problem, not a machine learning problem. GPT-4, LLaMA, and Mistral were all trained on datasets built by pipelines that processed petabytes of raw web crawl data (Common Crawl, GitHub, books, Wikipedia) through the same core stages.
The same pipeline architecture applies at smaller scale for fine-tuning: taking a pre-trained model and training it further on a domain-specific corpus (medical records, legal documents, code). The pipeline is smaller, but deduplication, quality filtering, and tokenization steps are identical.
Two pipeline shapes show up in practice. Pre-training pipelines crawl Common Crawl, GitHub, books, and Wikipedia, scale to trillions of tokens, run distributed on Ray or Dask across many machines, and output packed token sequences in Parquet or Arrow. Fine-tuning pipelines crawl domain-specific sources (docs, PDFs, APIs), scale from millions to billions of tokens, often fit on a single machine or small cluster, and output instruction-formatted JSONL for supervised fine-tuning (SFT).
LLM pipelines are the foundational data layer beneath every modern LLM. Without them, no training run is reproducible, no dataset is auditable, and no model gets shipped twice.
Master LLM Pipelines in 6 hours, hands-on.
From async web crawling and MinHash deduplication to BPE tokenization, sequence packing, and HuggingFace Hub publishing. Builds a complete billion-token-scale pipeline.
Why do LLM Pipelines matter?
- Near-duplicate removal stops models from memorizing repeated patterns instead of generalizing
- PII masking with NER keeps training data legally compliant — no leaked names, emails, or SSNs
- Perplexity and toxicity filters retain only high-quality text, lifting downstream eval scores
- Sequence packing fills the context window during training, often doubling GPU utilization
- Dataset cards and HuggingFace Hub publishing give every training run a full lineage trail
- Reproducible pipelines mean you can re-run a dataset build months later with identical output
How does an LLM pipeline work?
Every LLM data pipeline has four core stages. Each stage outputs to the next via Parquet files or Arrow streams, which makes the pipeline restartable and auditable.
- Collect — async web crawl with Scrapy for static HTML or Playwright for JS-rendered SPAs, respect
robots.txt, rate-limit per domain, extract clean text withtrafilaturaor BeautifulSoup - Clean — exact-dedupe by URL and content hash, near-dedupe with MinHash + LSH (
datasketch), filter low-quality docs by perplexity (kenlm), strip toxic content, mask PII with SpaCy NER or Microsoft Presidio - Tokenize — convert text to integer token IDs with
tiktoken(OpenAI BPE) orsentencepiece(Google), pack short documents together to fill the context window (e.g. 2048 tokens), separate with end-of-text tokens - Package — write to Parquet or Arrow for distributed training, generate a dataset card with lineage and statistics, push to HuggingFace Hub or an internal artifact store
MinHash near-duplicate detection with datasketch:
from datasketch import MinHash, MinHashLSH
lsh = MinHashLSH(threshold=0.8, num_perm=128)
def get_minhash(text: str) -> MinHash:
m = MinHash(num_perm=128)
for word in text.split():
m.update(word.encode("utf8"))
return m
duplicate_ids = set()
for doc_id, text in documents:
m = get_minhash(text)
if lsh.query(m):
duplicate_ids.add(doc_id) # near-duplicate found
else:
lsh.insert(doc_id, m)
BPE tokenization with sequence packing via tiktoken:
import tiktoken
import pyarrow as pa
import pyarrow.parquet as pq
enc = tiktoken.get_encoding("cl100k_base")
CONTEXT_LEN = 2048
def pack_sequences(texts, ctx_len=CONTEXT_LEN):
buffer, packed = [], []
for text in texts:
tokens = enc.encode(text)
buffer.extend(tokens + [enc.eot_token])
while len(buffer) >= ctx_len:
packed.append(buffer[:ctx_len])
buffer = buffer[ctx_len:]
return packed
sequences = pack_sequences(clean_texts)
table = pa.table({"input_ids": sequences})
pq.write_table(table, "dataset.parquet")
LLM pipeline vs RAG vs standard ETL
LLM pipelines sit at the intersection of classic data engineering and modern AI infrastructure. Two comparisons matter most:
| Dimension | LLM Pipeline | RAG Pipeline | Standard ETL |
|---|---|---|---|
| When it runs | Offline, before training | Online, per query | Scheduled batch |
| Output | Token sequences (Parquet) | Embeddings in a vector store | Rows in a warehouse table |
| Latency budget | Hours-days (throughput) | Milliseconds (latency) | Minutes-hours |
| Dedupe strategy | MinHash + LSH (semantic) | Per-document hash | Primary key dedupe |
| Quality signal | Perplexity, toxicity | Retrieval hit rate, MRR | Schema + null + range checks |
| Updates how | Re-train model on new data | Re-index documents | Re-run pipeline |
The core skills transfer: distributed processing, data quality, lineage, and incremental processing are the same in all three. What differs are the transformations (text and tokens vs structured columns) and the success metric (training loss vs retrieval precision vs row-count SLA).
Crawling: Scrapy vs Playwright
For the collect stage, the choice of crawler depends on whether the target sites render content with JavaScript:
- Scrapy — high-throughput async crawling framework, built-in
robots.txtand rate limiting, static HTML only. Best for large-scale static content. Thousands of pages per minute on a single machine. - Playwright — headless browser that renders JavaScript. Slower and more resource-heavy. Required for SPAs and authenticated pages.
Most LLM dataset pipelines use Scrapy as the primary crawler and fall back to Playwright for the subset of sites that need JS execution. Mixing the two keeps throughput high while preserving coverage.
Build a real LLM ingestion pipeline end-to-end.
Async Scrapy crawler, MinHash dedupe, SpaCy PII masking, BPE tokenization with sequence packing, Parquet output, and HuggingFace Hub push with a full dataset card. Mentor-reviewed.
Common mistakes (and what to do instead)
- Skipping deduplication — web crawl data contains massive near-duplication. Without MinHash/LSH, models memorize repeated patterns instead of learning language. Deduplication typically removes 30–60% of a raw crawl.
- Mismatching tokenizers between training and inference — if you tokenize training data with
cl100k_basebut run inference with a LLaMA sentencepiece tokenizer, token IDs are incompatible and model output is garbage. Pin the tokenizer version in the dataset card. - No sequence packing — wasting the context window — naive batching pads short docs with zeros, wasting compute. Sequence packing concatenates multiple short documents into a single 2048-token sequence separated by end-of-text tokens, often doubling training throughput.
- Storing token arrays as JSON or CSV — token ID arrays are large integers best stored in columnar binary formats (Parquet, Arrow). JSON inflates file size 3–5x and serialization becomes the throughput bottleneck.
- No PII masking — names, emails, and phone numbers in training data create legal and compliance risk. SpaCy NER or Microsoft Presidio should run before tokenization, not after.
- No dataset lineage — without a dataset card recording sources, filters, dedupe stats, and tokenizer version, you cannot reproduce or audit a training run six months later.
Who is an LLM pipeline for?
LLM pipelines are for data engineers, ML engineers, and AI platform engineers building the data foundation under language models. If your team is fine-tuning models, training models from scratch, or feeding embeddings into a RAG system, you are building (or should be building) an LLM pipeline.
Teams that benefit most:
- AI platform teams assembling pre-training or fine-tuning corpora at billion-token scale
- ML teams fine-tuning open models (LLaMA, Mistral, Qwen) on domain-specific text
- Data engineering teams extending ETL skills into unstructured-text territory
- Research labs building reproducible evaluation datasets with full lineage and dataset cards
Frequently asked questions
Start shipping.
Three steps from a guide to a job-ready portfolio. Pick one and start now — the rest will follow.
Take the skill
Self-paced module with code, exercises, and a deliverable. Free preview, paid completion.
Start S0X · Llm Pipeline →Ship the project
Production-grade build with starter kit + mentor code review. The artifact that gets you interviews.
Open P0X · Llm Ingestion Pipeline →Pick a career path
The full progression — skills + projects + interview prep — for the role you actually want.
See paths →