Building LLM-Driven Quantitative Data Pipelines: A Practical Guide
This article walks through a practical approach to building a quantitative data pipeline with LLM assistance, using market data ingestion as the first step. It explains why one-shot prompts tend to fail, how to align on symbols before automating, how to structure prompts with explicit acceptance criteria, how to design a normalized and extensible schema, and how to add progress visibility, retry and rate-limiting logic, idempotency, and validation checks. The goal is to turn a one-off conversation into a maintainable engineering asset.
1. The Starting Problem: Why a “One-Sentence Requirement” Goes Off the Rails
In real engineering work, handing a long requirement to an LLM in one shot and expecting it to complete everything reliably rarely produces stable results. The issue is not model capability. It is that the task lacks verifiable intermediate states: fuzzy requirement boundaries, undefined data structures, and failures that cannot be localized. The model fills the gaps by guessing, so the output naturally diverges.
A more reliable approach is to break the goal into a workflow, have a human confirm the key checkpoints, and let the model handle single-point implementation. The example below uses the first step of building a stock backtesting and analysis system, namely market data ingestion and persistence, to show a workable way to move forward.
2. Align on Entities First, Then Automate
The first step is not writing code. Instead, have the model extract symbol names and codes from existing trade records, then review them manually. The value of this step is establishing a single trusted list of symbols. Every later ingestion, cleaning, and backtesting step is based on it.
It is best to persist the list as a structured file rather than leaving it scattered across a conversation:
{"symbols": [{"code": "600000", "market": "SH", "name": "Sample Co."},{"code": "000001", "market": "SZ", "name": "Sample Bank"}],"adjust": "qfq","start_date": "2015-01-01"}
One point needs emphasis: the adjustment method, date range, and field definitions must be fixed in the first step. Otherwise, later data revisions will make backtest results non-reproducible.
3. Layered Prompt Writing
Rewrite a large goal such as “build a system” into “build a minimal working feature,” and state four categories of constraints explicitly in the prompt: data source priority, config file location, storage requirements, and observability requirements. Example:
Goal: Implement the market data ingestion task (first step only, no backtesting)Symbols: Read ./symbols.jsonData source: Prefer the locally wrapped market data interface; fall back to a backup source on failureConfig: Interface docs and credentials go in ./config/datasource.md; do not hardcode them in codeStorage: Write to a local relational database; normalize the schema and reserve extension fieldsObservability: Console output shows overall progress, current symbol, success/failure counts, and elapsed timeConstraint: A single symbol failure must not abort the whole task; failed items go to a retry queue
The key to this style is turning implicit expectations into explicit acceptance criteria, so the model output can be checked item by item.
4. Data Model: Balancing Normalization and Extensibility
Market data is typical time-series data. A layered modeling approach is recommended:
- Metadata layer: symbol table (code, market, name, listing status) and adjustment factor table.
- Fact layer: daily bar table (trade date, open/high/low/close, volume, amount, adjustment flag) and intraday table (timestamp, price, volume).
- Ops layer: ingestion task table, failed retry table, and data quality check table.
CREATE TABLE daily_bar (symbol VARCHAR(16) NOT NULL,trade_date DATE NOT NULL,open DECIMAL(18,4),high DECIMAL(18,4),low DECIMAL(18,4),close DECIMAL(18,4),volume BIGINT,amount DECIMAL(20,2),adjust_type VARCHAR(8) NOT NULL DEFAULT 'none',updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,PRIMARY KEY (symbol, trade_date, adjust_type));
The composite primary key is naturally idempotent: repeated ingestion only overwrites and never inserts duplicates. Reserving adjust_type and updated_at keeps the schema backward compatible. The intraday table is best partitioned by date to avoid single-table bloat.
5. Progress Visibility: Make the Process Observable
The requirement “I want to see progress” is not a courtesy. It reflects control. Achievable output forms:
[Progress] 128/512 symbols done | success 121 | failed 3 | retrying 4 | elapsed 00:06:12[Current] 600000 daily 2015-01-01 ~ 2024-12-31 wrote 2431 rows[Failed] 000001 intraday 2024-11-03 hit rate limit, entered retry queue (attempt 1)
Engineering recommendations: a task status table records each symbol’s state, attempts, and last_error; logs are output by level; elapsed time is printed at key stages. This way, even after an interruption, the job can resume from the checkpoint.
6. Fault Tolerance, Rate Limiting, and Idempotency
Ingestion tasks commonly hit three problems: interface rate limits, network jitter, and missing fields. Corresponding strategies:
- Exponential backoff retries with a maximum attempt count and dead-letter records;
- Token bucket or fixed-interval rate limiting that respects the data source quota;
- Field-level validation (missing, out of range, discontinuous dates) written to a quality table rather than silently dropped;
- End-to-end idempotency, ensuring any rerun produces the same result.
About the “hang” behavior during a run: in most cases it is caused by a long task producing no output, waiting on a connection, or unflushed buffers. Mitigations include disabling output buffering, setting request timeouts, splitting large tasks into small batches, and persisting and logging each step, so human intervention only requires restarting the current batch.
7. Testing and Acceptance
Before handing the pipeline to backtesting, complete at least three types of validation: sampling comparison (randomly pick several symbols and check against the official definition), continuity checks (missing trading days, duplicate rows), and adjustment consistency checks (price relationships under different adjustment methods over the same range). Acceptance criteria should be written as executable scripts and included in daily scheduling.
8. Summary
LLMs are well suited to “single-point implementation with clear boundaries,” while humans define the workflow and acceptance. Making the symbol list, field definitions, storage conventions, progress output, and fault-tolerance strategy explicit one by one is what turns a one-off conversation into a sustainable engineering asset. If further combined with general capabilities on Baidu AI Cloud such as container platforms, object storage, log services, and monitoring and alerting, it can close the loop on task scheduling and hosting, data archiving, and anomaly alerting, taking the data pipeline from “it runs” to “it is operable.”
