r/AIcodingProfessionals • • 3d ago

Discussion How do you prevent an AI coding agent from duplicating existing ETL logic?

I've been experimenting with Claude Code on unfamiliar ETL pipelines, and one risk keeps standing out.

An AI agent can generate a technically correct transformation while unknowingly creating a second implementation of an existing business rule. The code runs, the tests pass, and you now have two versions of the same logic quietly drifting apart.

The workflow I've been testing to catch this before it ships:

  1. Map the pipeline before changing anything.

  2. Trace the target field or rule through upstream and downstream dependencies.

  3. Search for similar transformations across SQL, PySpark, notebooks, and configuration.

  4. Ask the agent to produce an implementation plan, not code.

  5. Review whether the plan reuses or extends existing logic, rather than introducing a parallel path.

  6. Generate code and tests only after approving the plan.

  7. Compare the final changes against the approved scope.

The lesson that stuck with me: passing tests is not enough. Tests confirm the new logic works, but they don't tell you the same rule already exists somewhere else in the codebase.

For people using AI coding tools on ETL or data pipelines — how are you checking for duplicated business logic before accepting generated changes? Curious if others have a more systematic approach than what I'm doing, or if this is mostly still ad hoc for everyone.

4 Upvotes

3 comments sorted by

2

u/pvera 3d ago

Force it to recheck the source of truth. It wouldn't hurt to periodically check if your code, specs, etc. are consistent across.

1

u/SudhansuDash 3d ago

Agreed on the periodic consistency check — that's basically what steps 3 and 7 in my workflow are trying to do (searching for similar transformations before changes, then comparing the final diff against the approved plan afterward). Curious how you define 'source of truth' in practice though — do you mean the spec/requirements doc, the existing codebase itself, or something like a data dictionary/metadata catalog? In ETL work specifically, I've found the codebase and the documented business rules can drift from each other, so 'recheck against source of truth' sometimes just pushes the same problem one level up.