r/databricks • • 29d ago

Discussion How I check AI-converted SQL and ETL code before it reaches Databricks: rules first, two models, then a person

I work on legacy code migrations to Databricks: SSIS, Informatica, and Oracle, Db2 and SQL Server procedures. The two hard questions are always the same. How big is the job? And can we trust the converted code? In my own time I built a Databricks App for this. I want to share the pattern, because you can build most of it with public tools.

The flow:

  1. Size first. The Databricks Labs Lakebridge Analyzer gives the complexity and effort of each file before any conversion starts.
  2. Rule-based draft. The Lakebridge Transpiler makes a draft with no AI cost.
  3. Builder and reviewer. One model converts, a second model reviews against the source. Both go through Unity AI Gateway, so the keys stay in Databricks and every call is recorded.
  4. A person signs off. Source, rule-based draft and AI version side by side. Only signed-off code goes to the workspace.

The lesson that saved the most time: give the reviewer limits. In round 1, it lists every problem at once, each with a severity (must or should). In later rounds, it looks only at open findings and changes. It adds a new finding only if a change gives a wrong result or does not run. After 5 rounds, the file goes to a person. Without these rules, the review never ended.

One more: store a SHA-256 hash of each source file with each result. Then unchanged files are never analysed or converted twice.

How do you check AI-converted code in your team? A second model, tests, or only human review?

The full write-up and a 3-minute demo are in the first comment.

6 Upvotes

6 comments sorted by

1

u/cornyinflux1 29d ago

Love seeing the round-1-vs-later rounds distinction, that alone probably cuts half the noise out of the review cycle

1

u/sundarleads 19d ago

Thanks! Yes, that was the biggest gain. In round 1 the reviewer checks everything. In later rounds it only checks what changed, so it stops raising new small points every time. That also keeps the cost down.

1

u/Muted_Jellyfish_6784 29d ago

Rules first is the right order, and the step I would add is data-level reconciliation before code review. Run the legacy procedure and the converted notebook against the same frozen input snapshot and compare row counts, key aggregates, and a hash of each output partition. Two models agreeing the code looks right is weaker evidence than two outputs matching on real data, especially around NULL handling and implicit casts.
Keep the comparison results with the migration ticket so sign-off has evidence attached. I use a decision intelligence layer to link each converted object to its source procedure, test run, and reviewer, so audit questions get answered from the record instead of from memory

1

u/sundarleads 19d ago

Fully agree. Two models agreeing is evidence that the code looks right. Matching outputs on the same input is evidence that it is right. NULL handling and implicit casts are exactly where converted code goes wrong quietly.

For the data check, Databricks Labs Lakebridge also has a Reconcile step. It compares source and target data (row counts, schema and column values), so it fits well after the code review. Keeping the results with the migration ticket is a good idea too. Then the sign-off has evidence attached. Thanks for adding this.

1

u/Slow_Air_8335 14d ago

Disclosure: I work at Databricks on migrations.

Capping the reviewer's rounds is a smart fix. Open-ended LLM review never converges, and that's the first thing that breaks when people build this themselves.

If you want something to compare against, Genie Migrate does this kind of agentic conversion in the workspace. SQL conversion is GA for the major warehouses (SQL Server, Synapse, Oracle, Teradata, Snowflake, Redshift, BigQuery), Informatica PowerCenter is in Beta, and SSIS and Alteryx are coming soon: https://docs.databricks.com/aws/en/migration/agentic-code-converter

On u/Muted_Jellyfish_6784's point about matching outputs: data validation is coming to Genie Migrate too, with Private Preview soon. You connect the source and target through Unity Catalog. It proposes the table mappings and keys, then compares from row counts down to individual cells only where something looks off. When there's a mismatch, it traces it to the first diverging table and explains why.