Compilation happens before dbt can send model SQL to the warehouse.
A missing ref, an undefined macro, or an unclosed Jinja block can fail there. Read the file name and line number, then inspect the generated SQL after fixing the template. A warehouse syntax error happens later and needs the rendered query, not just the original template.
A refactor should preserve the agreed result while making its structure easier to maintain. Move a repeated cleanup into a staging model, replace copied SQL with ref, and compare the output on awkward records.
Duplicates and missing keys are where apparently harmless rewrites often change the grain. These exercises deliberately begin with different classes of defect. Repair the smallest relevant part and keep the business rule visible so another analyst can review the change.