AI Tools for Data Analysts - Make Coders Jealous · Lesson 2 of 3
Verify AI-Generated Analysis and Code
Review generated formulas and scripts with tests, independent calculations, and data-quality checks.
Lesson
1. Introduction
AI-generated code can be syntactically valid and still answer the wrong question. Verification compares its behavior with explicit definitions and known examples before the code is used on important data.
2. Understand the concept
Review every join, filter, conversion, and aggregation. Run the proposal on a tiny hand-checkable example, test null and duplicate cases, and reconcile totals with a trusted source. Treat model-generated explanations and citations as claims that need evidence.
3. Syntax and interpretation
expected_total = 30
calculated_total = sum([10, 20])
assert calculated_total == expected_totalA small deterministic test detects basic errors. Real reports also need schema, row-count, key, and reconciliation checks.
4. Apply it to an analysis
Review generated formulas and scripts with tests, independent calculations, and data-quality checks. Start with a small, known example and state what each row or value represents. After the transformation, check row counts, types, keys, and units against the original data. If an assumption fails, stop and investigate instead of presenting the output as a valid result.
5. Common mistakes
- Trusting a plausible chart without checking source rows and aggregation.
- Running generated code with broad filesystem, network, or database permissions.
6. Practice task
An AI query reports twice the expected revenue. Name two likely checks.
7. One possible solution
Check join cardinality and duplicate keys, then compare row counts and revenue before and after each join/filter.8. Summary and next step
Review generated formulas and scripts with tests, independent calculations, and data-quality checks. Continue to the next course section and apply this foundation to a different analytics tool or workflow.
Visual guide
Working through Verify AI-Generated Analysis and Code
-
Step 01
Define
State the question, data grain, and expected output.
-
Step 02
Apply
Use the method and check its assumptions on a small example.
-
Step 03
Verify
Reconcile the result and communicate limitations.
Code examples
ids = [101, 102, 103]
assert len(ids) == len(set(ids))
Passes when all IDs are unique.
line_total = sum([12, 8, 10])
reported_total = 30
assert line_total == reported_total
Both totals equal 30.
Key points
- Review generated formulas and scripts with tests, independent calculations, and data-quality checks.
- Check the result against the stated data definition and a representative example.
- Record assumptions and report data-quality limitations rather than hiding them.
Check your understanding
Practice
Your learning progress