A Practical Guide to LLM-Driven Data Engineering Workflows
This article presents a practical approach to data engineering with large language models (LLMs). Instead of handing a complex task to the model in a single prompt, it breaks the work into five verifiable steps: entity extraction with human confirmation, localizing API documentation, automated API availability checks, data ingestion with observable progress, and validation with retrospective review. It includes directory conventions, prompt constraints, a sample API probing function, a database schema, and collaboration practices such as idempotent writes and failure isolation to keep LLM output controllable and reusable.
1. Why “One-Shot Requirements” Get Out of Control
When using large language models (LLMs) for data engineering tasks, many developers describe all their requirements at once and wait for the model to finish everything automatically. This can work for simple tasks with a closed context. However, once a task involves multiple data sources, inconsistent field definitions, incremental versus full-load strategies, and storage design, the model’s output quickly drifts from expectations: messy directory structures, inconsistent naming, missing error handling, and invisible logs or progress. The result is often a full rollback and a restart.
A more reliable approach is to make the task flow explicit: humans define the process and acceptance criteria, while the model implements one step at a time. The core principle is that every step produces a verifiable artifact, such as a checklist, a runnable script, a test report, or a table schema description. If one step goes wrong, the rollback cost is limited to that single step.
2. Overall Method: Five Verifiable Steps
- Entity extraction and human confirmation: Extract target names and codes from unstructured text, then verify them manually before proceeding.
- Localizing API documentation: Fetch public API documentation and organize it into local Markdown files to build a searchable knowledge base.
- API availability verification: Generate standalone test scripts for candidate APIs, verify connectivity, permissions, fields, and rate limits one by one, and output a test report.
- Data ingestion: Pull daily and intraday data according to the target list, write it into a well-structured, extensible local database, and output progress in real time.
- Validation and review: Check record counts, time coverage, nulls, and duplicates, and capture reusable prompt templates and directory conventions.
3. Step 1: Entity Extraction and Human Confirmation
Do not hand the model a vague goal such as “analyze the trade orders.” First, ask it to do only one thing: extract stock names and codes from the text and output them in a table with fields for name, code, source line number, and confidence. After human confirmation, save the result as a reference table or configuration file that serves as the single input source for all subsequent steps.
The benefits are clear input boundaries, so downstream scripts no longer need fuzzy parsing, and no “guessing” by the model between names and codes, which reduces mismatches.
4. Step 2: Localizing and Structuring API Documentation
Giving the model the API documentation URLs and asking it to fetch and organize them into local Markdown files is a key step for stability. Once localized, the model no longer depends on changes to external page structures, reference paths are explicit, and errors are easier to locate.
A recommended directory convention:
project/├── docs/ # Localized API documentation (Markdown)├── config/ # Target list and data source configuration├── scripts/ # Ingestion and test scripts├── reports/ # API test reports and data validation reports└── db/ # Local database files and migration scripts
The prompt should state explicit constraints: only documents under docs/ may be referenced; do not invent API names or parameters that do not exist; mark uncertain fields as “to be confirmed.”
5. Step 3: Automated API Availability Verification
Before ingesting data at scale, run an “API health check.” Have the model generate a minimal runnable test for each candidate API: request only a small sample, print the status, field list, and elapsed time, and summarize the results into a report. The report should include at least the API name, availability, permission requirements, returned fields, rate-limit behavior, and notes.
Illustrative verification logic:
def probe(api, params):try:df = api(**params) # Fetch only a minimal samplereturn {"api": api.__name__, "ok": True,"rows": len(df), "fields": list(df.columns)}except Exception as e:return {"api": api.__name__, "ok": False, "error": str(e)}
The principle is “verify first, batch later.” When data comes from multiple sources, produce a separate report for each, then designate primary and backup sources based on field completeness and stability. This avoids discovering permission or field gaps only during the batch stage.
6. Step 4: Data Ingestion and Observable Progress
Design the database for extensibility: use a dedicated metadata table to record targets, data sources, sync batches, and update times; use a unified fact table for market data with consistent field names and types; index the time dimension and reserve a partitioning or sharding strategy.
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,batch_id VARCHAR(32),PRIMARY KEY (symbol, trade_date));
Progress observability is equally important. Require scripts to output, for each target, “current index/total, rows written, elapsed time, and failure reason,” and write failed items to a retry queue. This lets users judge progress at any time instead of facing a black box with no output for a long time.
7. Stability and Collaboration Details
- Step-by-step execution: accept each step before moving on, avoiding loss of control over long chains of tasks.
- Explicit constraints: state input paths, output formats, and prohibited actions in the prompt.
- Idempotent writes: use primary keys and batch IDs so repeated runs produce no dirty data.
- Failure isolation: a single target’s failure does not affect the whole run; log it and continue.
- If the runtime becomes unresponsive for a long time, stop the current step, reduce the task granularity, and rerun; this usually restores normal operation.
8. Conclusion
LLMs are good at single-point implementation but not at carrying a complex workflow in one shot. Keep process definition in human hands, delegate implementation to the model, and constrain output with four levers: documentation localization, API pre-verification, standardized ingestion, and visible progress. This minimizes the probability of “runaway generation” and forms a sustainable, reusable data engineering collaboration model.
