A Practical Guide to LLM-Driven Data Engineering Workflows
This article presents a practical guide to using large language models in data engineering. Instead of handing a full requirement to an AI coding tool in one shot, it treats the model as an execution unit within a human-designed workflow. It walks through a layered data platform architecture, then breaks delivery into five verifiable steps: extraction and confirmation, localizing and testing API documentation, normalized database design, observable and fault-tolerant collection, and quality checks for backtesting readiness. It also shares prompt structures, common pitfalls, and mitigation practices. Readers will learn how to keep AI-generated data pipelines structured, extensible, and trustworthy.
1. The Problem: Why a One-Sentence Requirement Rarely Delivers a Reliable System
In data engineering, developers often hand a complete requirement to an AI coding tool in a single prompt, expecting it to automate the entire pipeline from data acquisition to database ingestion. The results are usually disappointing: arbitrary directory structures, inconsistent field naming, missing error handling, and even long periods of no response during extended tasks. The root cause is not model capability but the absence of task granularity and verification mechanisms.
A more reliable approach is to treat the model as an execution unit while humans own workflow design and acceptance. Developers should first map out the data flow: how the target list is determined, which APIs the data comes from, how it is stored, how quality is validated, and how it supports later backtesting and analysis. Each step needs clear inputs, outputs, and acceptance criteria, and the model only produces runnable code within a controlled scope.
2. Overall Architecture: A Layered, Decoupled Data Foundation
Divide the system into five layers that communicate through explicit contracts, preventing a generative model from improvising across layer boundaries.
- Instrument management layer: maintains metadata such as ticker symbols, names, listing status, and market.
- Collection scheduling layer: generates tasks by instrument and period, controls concurrency and rate, and records the context of each run.
- Adapter layer: wraps differences between data sources behind a unified interface, hiding field and pagination variations.
- Storage layer: a normalized local database that separates the raw layer from the processed layer.
- Observability layer: progress, logs, failure retries, and data quality reports.
A sample directory structure:
data_platform/adapters/ # data source adaptersscheduler/ # task orchestration and rate limitingstorage/ # table creation and writesquality/ # validation rulesreports/ # API tests and collection reports
3. Step 1: Let the Model Only Extract and Confirm
Keep the first step deliberately simple. For example, extract only the instrument names and symbols involved from existing trade records to form a candidate list, then have a human confirm it. This delivers three benefits: it verifies whether the model understands the context accurately; it catches errors at the cheapest stage; and it produces the authoritative input that every later step depends on.
Acceptance criteria must be quantifiable: number of entries, whether symbol formats are valid, whether duplicates exist, and the number of discrepancies after human confirmation. Only when the list is frozen can the next step begin.
4. Step 2: Localize API Documentation and Verify Usability
Before actual collection, pull the data API documentation to a local file and rewrite it into structured documentation. Then have the model generate test code to verify each API one by one: connectivity, authentication method, parameter constraints, response structure, and rate-limiting behavior. The results are consolidated into a test report containing at least: API name, whether it is usable, maximum records per request, granularity of time parameters, and categories of failure reasons.
The point of this step is to surface uncertainty early. If data source field changes, permission differences, and rate limits are exposed during design, the cost of reworking later code is minimal. Meanwhile, the local documentation becomes the model’s single source of truth, significantly reducing cases where it fabricates parameters from memory.
Note that credentials should be injected through environment variables or a local configuration file and added to ignore rules so they are not leaked with committed code.
import osTOKEN = os.environ["DATA_SOURCE_TOKEN"] # never hardcode in source
5. Step 3: Normalized Database Design with Extensibility in Mind
Database design should follow the principle “no transformation in the raw layer; the processed layer must be rebuildable.” The raw layer is split or partitioned by data source and period, preserving original fields and fetch timestamps. The processed layer generates wide tables through repeatable transformations for analysis.
Reference table definition:
CREATE TABLE ods_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),fetched_at TIMESTAMP NOT NULL,PRIMARY KEY (symbol, trade_date));
Extensibility shows up in three places: the primary key provides natural deduplication and supports repeated collection; adding a data source only requires implementing the unified adapter interface; and adding a new period (daily bars, intraday) is done by adding partitions or table families without touching existing code.
6. Step 4: Progress Visibility and Fault Tolerance During Collection
Long-running tasks must be observable. Each collection run should emit structured progress: number of instruments completed, current instrument, counts of succeeded and skipped records, failure reasons, and estimated time remaining. Also introduce resumable checkpoints, using “instrument + period + time range” as the completion marker so an interrupted task can continue from where it stopped.
for i, symbol in enumerate(symbols, 1):if is_done(symbol, period, start, end):continuetry:rows = adapter.fetch(symbol, period, start, end)storage.upsert(rows)mark_done(symbol, period, start, end)except TransientError:retry_with_backoff(symbol)log_progress(i, len(symbols), symbol)
For cases of prolonged no response, set timeouts and a heartbeat mechanism so the scheduling layer actively terminates and restarts the task instead of relying on manual observation.
7. Step 5: Quality Validation and Backtesting Readiness
Ingestion does not mean usable. Define four categories of checks: completeness (whether trading days are missing), consistency (the high is not lower than the low, and the close falls within the range), timeliness (whether the fetch timestamp lags), and duplication (primary key conflict ratio). Validation results are written to a report, and instruments with anomalies automatically enter a re-collection queue.
Only when the quality report passes its thresholds is the data marked as “ready for analysis.” The backtesting workflow then reads only from the processed layer, preventing dirty data from entering strategy evaluation.
8. Collaboration Experience: Keep the Model Inside the Workflow
The key lesson in practice is process first, acceptance step by step. A reusable prompt structure has four parts: role and goal, location of input materials, constraints (data source priority, storage conventions, logging requirements), and acceptance criteria. For example:
Goal: fetch daily bar data for a given instrument list and store itInputs: local API documentation path, instrument list fileConstraints: prefer verified usable APIs; tables must include a primary key and fetch timestamp; emit progress logsAcceptance: sample and compare record counts and values; failed items must include a failure category
9. Common Pitfalls and How to Avoid Them
- Delivering the whole pipeline at once: switch to staged delivery where each stage runs and passes acceptance independently.
- Hardcoded credentials: route everything through environment variables and ignore rules.
- No deduplication design: enforce write semantics with a business primary key.
- Missing timeouts and retries: distinguish retryable from non-retryable errors.
- Missing documentation: produce API test reports and a data dictionary alongside the code and put them under version control.
10. Conclusion
Using AI coding tools in data engineering pays off through control, not full automation. With a layered architecture, documentation first, step-by-step acceptance, observable progress, and quality gates, developers keep the efficiency gains the model provides while ensuring the resulting system is clearly structured, extensible, and maintainable, giving later quantitative analysis and backtesting a trustworthy data foundation.
