Agentic Data Engineering in Practice
How AI Agents Build, Test, and Fix Data Pipelines — Without Breaking Production
Introduction: The Pipeline Changed Hands
Something changed in data engineering in 2026, and it was not a new database.
It was who holds the wheel.
For years, a data engineer wrote the pipeline: the ingestion, the transformation, the test, the fix at 2 a.m. when a source table changed its schema without telling anyone. AI helped — it completed code, it wrote SQL, it explained an error message. But it stopped when you stopped typing.
Agentic data engineering is different. An agent does not just suggest a snippet. It plans a task, runs code, observes the result, corrects itself, and repeats until the task is done — or until it knows it needs a human.
That loop is already shipping inside the platforms teams use every day. Databricks documents agents that create ingestion connectors and build pipelines in Python and SQL, and agents that detect failures and propose fixes validated in a sandbox. Snowflake, dbt, and Microsoft Fabric have shipped the same direction, each in their own way: a governed coding agent, a lifecycle agent grounded in lineage and contracts, a data agent that answers questions over governed data.
This pocketbook is a practical introduction to that shift. It is short on purpose. You will not learn a framework here. You will learn the loop, the three places it already works, and the guardrails that keep it from becoming a very expensive mistake.
By the end, you will have built a small agentic pipeline, wired it to n8n and MCP, and written the three checks that decide whether an agent is allowed to touch production at all.
Want the full version of this story?
The harness, the evaluation, and the production controls are in the author’s full books on Amazon. This pocketbook is the taste. The books are the meal.
Chapter 1. What Agentic Data Engineering Actually Is
A copilot suggests. An agent loops.
That is the whole difference, and it matters more than any model name.
A copilot sees your code, suggests the next ten lines, and stops. You are still the loop: you run it, you read the error, you fix it, you run it again.
An agent is given a goal — “ingest this CSV, clean it, load it into Delta, and tell me if anything looks wrong” — and it runs the loop itself:
- Plan. Break the goal into steps.
- Act. Write and run code, call a tool, query a table.
- Observe. Read the result, the error, the row count.
- Correct. Change the plan and try again.
- Stop. Finish, report, or escalate to a human when it cannot proceed safely.
In 2026, that loop moved inside the pipeline itself. The work that already works, in practice, is narrow and boring — and that is why it works:
- Triage. An agent reads a failed job, finds the failing step, and writes a summary a human can act on in two minutes instead of twenty.
- Test scaffolding. An agent writes the first version of a test — a schema check, a row-count check, a freshness check — from the table it just built.
- Documentation. An agent documents a pipeline from its lineage, its code, and its actual runs, instead of from a wiki page nobody updated.
- Fix proposals. An agent proposes a fix for a broken transformation, and runs it in a sandbox first, so a human can approve it before it touches production.
What does not work yet, without a human in the loop, is the rest: changing a production schema, writing to a production table, or deciding that a business rule has changed. Those stay behind human approval. That is not a limitation to work around. It is the design.
The rule for this book: an agent may propose anything. It may apply only what is reversible, tested, and logged.
Chapter 2. The Agent Loop, in Plain Python
You do not need a new platform to understand the loop. You need a small, boring harness that does the same thing every time.
Here is the shape, in Python. It is not a production system. It is the shape of one.
# agent_loop.py — the shape, not the whole system
def run_pipeline_task(task, max_attempts=3):
plan = plan_task(task) # 1. break the goal into steps
for attempt in range(max_attempts):
result = execute_step(plan) # 2. run code / call a tool
observation = observe(result) # 3. read logs, row counts, errors
if observation.ok:
return finish(result)
plan = correct_plan(plan, observation) # 4. change the plan
return escalate_to_human(task, plan) # 5. stop, and ask for help
Three details make this loop safe, and all three are easy to skip when you are excited:
A budget. Every loop needs a maximum number of attempts, a maximum number of tool calls, and a maximum cost. An agent without a budget is a loop that can run until your cloud bill notices. Set the budget in code, not in a prompt.
A log. Log the plan, every tool call and its result, and the final answer. If you cannot trace a bad table back to the step that created it, you will fix the wrong thing.
An escalation rule. Decide in advance what “I don’t know” looks like. A missing table, a schema change, a permission error — these are not things to guess around. They are things to stop on, and hand to a human with the evidence attached.
Write those three down before you write your first agent. They are the difference between a demo and a system.
Try it: one loop, one table
Pick one small, real task. Not “modernize the platform.” Something like: “Load this week’s sales CSV into a staging table, and report the row count and any nulls in the customer_id column.”
Run it with the loop above. Count how many attempts it took. Write down where it got stuck. That list — not the code — is your first production lesson.
Chapter 3. Your First Agentic Pipeline on Databricks
Databricks is where this becomes concrete for most data teams, because the data, the compute, and the governance already live there.
Here is a minimal, honest pattern. An agent writes a PySpark transformation. A human does not merge it blindly. A harness runs it, tests it, and only then lets it near a real table.
# transform.py — written by an agent, checked by a harness
from pyspark.sql import functions as F
def clean_sales(df):
return (
df
.withColumn("customer_id", F.trim(F.col("customer_id")))
.filter(F.col("customer_id").isNotNull())
.withColumn("amount", F.col("amount").cast("double"))
.filter(F.col("amount") > 0)
)
# checks the harness runs before anything is written
def check_sales(df):
assert df.filter(F.col("customer_id").isNull()).count() == 0
assert df.filter(F.col("amount") <= 0).count() == 0
return True
The agent’s job is to write clean_sales. The harness’s job is to run check_sales, plus two checks the agent did not write:
- A schema check. Did the columns arrive with the names and types we expected? If a source renamed
customer_idtocustomerId, stop here. - A freshness check. Is this data from today, or is it last Tuesday’s file with today’s name? If the source stopped updating, say so before you answer anything.
In Databricks, that harness lives where the pipeline lives: a notebook or a job, with Unity Catalog as the governance layer — who can read what, what lineage a table has, and what changed, and when. The agent proposes. Unity Catalog, the tests, and a human approve.
A practical rule: never let an agent write directly to a production table. Let it write to a staging table, run the checks, and only then promote the result. The extra step costs minutes. The missing step costs weekends.
Chapter 4. n8n as the Orchestrator: When Visual Workflows Win
Not every agent needs to be code. Some of the best agentic pipelines are the ones a team can see.
n8n is the orchestrator for those cases. It is a visual workflow tool: nodes, connections, retries, and webhooks you can trace with your eyes. For a data agent, that visibility is a feature, not a toy.
Use n8n when the pipeline is mostly coordination:
- A file arrives in a bucket. Trigger a workflow.
- An agent cleans it, checks it, and loads it.
- If a check fails, send a message to Slack, open a ticket, and stop — do not guess.
- If it passes, trigger the next job in Databricks, and log the run.
Use code — Python, a Databricks job, a Lambda function — when the pipeline is mostly computation: heavy joins, window functions, model inference, or anything that would be painful as a diagram.
A good hybrid looks like this:
New file in storage
→ n8n trigger (webhook / schedule)
→ Agent node: plan the load, write the PySpark step
→ Databricks job: run it in a sandbox, run the checks
→ If checks pass: promote to staging, notify the team
→ If checks fail: escalate to a human, with the log attached
The n8n workflow is the nervous system. Databricks is the muscle. The agent is the part that decides, in the moment, what to do next — inside the limits you set.
A practical rule: if you cannot draw the workflow on one page, it is too big for one workflow. Split it. Agents, like people, do better with small, clear jobs.
Chapter 5. MCP: Give Your Agent Safe Access to Data and Tools
An agent without tools is a very smart person locked in an empty room. It can reason, but it cannot do anything.
The Model Context Protocol — MCP — is how agents reach tools in 2026. It is an open standard, originally from Anthropic, now under the Linux Foundation’s Agentic AI Foundation. In its 2026-07-28 specification, MCP became stateless: no handshake, no session to manage, so a server scales like any other web service. It also added Tasks for long-running work, MCP Apps for interfaces shipped by the server, and a growing focus on authorization and governance.
You do not need to memorize the specification. You need the mental model:
- An MCP server exposes tools: “query this table,” “list files in this bucket,” “run this check.”
- An MCP client — your agent — calls those tools, and only those tools.
- The protocol is the contract in between: what a tool does, what it needs, and what it returns.
Here is the shape of a safe MCP tool, in Python. Notice what it does not do: it does not give the agent a database password, and it does not let it write anywhere it wants.
# mcp_server.py — the shape of a safe tool
# Tool: "sales_summary"
# What it does: reads from ONE governed table, returns aggregates only.
# What it cannot do: write, delete, or read any other table.
def sales_summary(start_date, end_date):
# The server, not the agent, owns the connection and the permissions.
rows = query_governed_table(
table="sales_curated",
start=start_date,
end=end_date,
)
return {"rows": len(rows), "total_amount": sum(r.amount for r in rows)}
Three rules for MCP in production:
- Least privilege, one identity per agent. An agent that reads sales should not also be able to delete users. Give it one identity, with the smallest permissions that let it do its job, and log everything it does under that identity.
- Read first, write later — much later. Start with read-only tools. Add a write tool only when you can name the exact check that runs before the write, and the exact rollback if it goes wrong.
- The server owns the secret. The agent never sees a password, a token, or a connection string. The MCP server holds the credential, and the agent only sees the tool.
MCP is the connectivity layer. Skills — small, reusable files that capture domain knowledge — are the other half of the 2026 stack, and they travel with the server. Together, they are why an agent built in 2026 can reach a SaaS app, a shared drive, or an internal database without a bespoke integration for each one.
Start with one server, three tools, and read-only access. That is enough to be useful, and small enough to be safe.
Chapter 6. Evals, Contracts, and Governance: The Part That Keeps You Employed
Here is the statistic that should shape everything in this book.
In 2026, most enterprises can build an agentic demo. Fewer than one in five, by the industry reports circulating this year, have one running reliably in production. And analysts warn that a large share of agentic projects will be cancelled — not because the models are weak, but because the cost is unclear, the business value is unclear, or the risk controls are weak.
Governance is not the boring part. Governance is the part that decides whether your agent survives its first quarter.
Three practices, in order:
1. Data contracts
A data contract is a promise between the producer of a table and everyone who consumes it: these columns, these types, this freshness, this quality. When a contract breaks, the pipeline stops before it writes bad data, and someone is paged with a clear message.
Write contracts for the tables your agent touches. An agent that reads a table without a contract is reading a rumor.
2. Evals
An eval is a small, repeatable test that answers one question: “Is the agent still good at this?”
Keep a small evaluation set — ten to twenty real examples, with the right answer attached. Run it every day, or every time you change a prompt, a model, or a tool. If the score drops, stop and look. Do not ship a prompt change because it “felt better in the demo.”
A useful eval for a data agent is not “did it sound smart?” It is: did it answer, did it cite the table it used, and did it stay in scope? If it cannot cite its source, it is guessing.
3. Cost and lineage
Log tokens, time, and cost per run. An agent that makes five large-model calls per request, with no cache and no short-circuit, becomes a bill before it becomes a product. Use a smaller model for classification and routing. Cache repeated lookups. Only call the large model when the decision actually needs it.
And keep lineage: which table, which run, which prompt version, which tool call produced this answer? In Databricks, Unity Catalog gives you that lineage for free, if you use it. Use it. When a user asks “why did the agent say that yesterday?”, lineage is the only honest answer.
The checklist before any agent touches production:
- A data contract exists for every table it reads or writes.
- An eval set exists, and it runs on a schedule.
- A budget exists: max attempts, max tool calls, max cost per run.
- Every run is logged: inputs, tool calls, outputs, and score.
- A human approves schema changes and production writes.
- A rollback exists, and someone has tested it.
If you cannot tick all six, you do not have a production agent. You have a very good demo. That is fine — as long as you know which one it is.
Chapter 7. From One Pipeline to a Platform: The 30-Day Playbook
You do not need a platform team to start. You need thirty days, one pipeline, and the discipline to stop at each gate.
Days 1–7: Pick one pipeline, and watch it. Choose the pipeline that fails most often, or the one a human babysits every week. Do not build an agent yet. Just log it: how often it fails, why, and how long the fix takes. That log is your business case.
Days 8–14: Build the loop, read-only. Build the agent loop from Chapter 2, with read-only MCP tools. Let it triage failures and propose fixes. Let it write tests and documentation. Do not let it write to production. Measure: how many triages were right? How much time did they save?
Days 15–21: Add one safe write. Pick one reversible, tested write — a staging table, a sandbox run, a draft report. Add the checks from Chapter 6. Run it for a week. If the eval score holds and the cost is sane, keep it. If not, roll it back and write down why.
Days 22–30: Decide what to scale. Now you have evidence, not enthusiasm. Either scale the loop to a second pipeline, or fix the one thing that kept breaking — the contract, the eval, the cost. Do not add a second agent until the first one is boring. Boring is the goal. Boring means reliable.
At the end of thirty days you will have one of two honest outcomes, and both are wins: a small agentic pipeline that works, with the evidence to prove it — or a clear, written reason why this particular pipeline is not ready yet, and what would make it ready. Both beat a demo that impressed a room and died the following Monday.
What to Read Next
This pocketbook was the taste. The full books go deeper, with the harness, the evaluation, and the production controls in full.
Start here, in the author’s catalogue on Amazon:
- Automate Anything with AI Agents — the introduction: how to build your first agent. Find it on the author’s Amazon page →
- Autonomous AI Employees with n8n and MCP — orchestration and tools, the n8n and MCP patterns from Chapters 4 and 5 in full. Find it on the author’s Amazon page →
- Harness Engineering for Data Agents on Databricks — structure, tests, evaluation, and governance, the full version of Chapter 6.
- Production AI Agents: From Prototype to Production with Databricks, n8n, and MCP — the closing book in the AI Agents in Practice series, when it is published: harness, evaluation, deployment, and the launch checklist. Author’s Amazon page →
If you built the loop in Chapter 2, ran the checks in Chapter 3, or wired the n8n workflow in Chapter 4, you already did the hard part. The next step is not a bigger model. It is a smaller, better-guarded loop — run every day, logged, evaluated, and boring enough to trust.
Build that. Then build the next one.
More free pocketbooks in this series:
- MCP in Production 2026 — Pocketbook No. 2: how to ship MCP servers that are secure, governed, and reliable.
- From Demo to Production: Agent Reliability & Evaluation — Pocketbook No. 3: how to close the production gap and ship AI agents you can trust.
Keep reading — the full books are on Amazon.
Browse all books by Leandro Calado Ferreira on Amazon →
Also free on this site: Harness Engineering for AI Coding Agents