Skip to content

DS 202 · Module 2

Trustworthy AI Data Science: Verification, Reproducibility, and Governance

Extend Module 1's AI-assisted loop into debugging, layered verification, reproducibility and provenance, privacy and governance, and finally an auditable Independent Lab.

Start Section 1
0 / 5 completed
Sync my progressJoin a session to keep progress across devices and share it with your instructor

Info

After you join, your completed lesson numbers are sent to your instructor together with your learner code, so they can see your progress. Use the codes your instructor gave you, and do not enter your name, company secrets or other personal data. Progress is kept with the rest of that session's data.

Learning objectives

  • Separate syntax/runtime errors from silent analytical errors
  • Verify source data, transformations, methods, outputs, and narrative claims in layers
  • Record environment, data version, prompts, generated code, edits, and outputs
  • Decide whether data may be sent to an AI service; minimize data; redact/synthesize when needed
  • Deliver analysis plus prompt log, code diff/review, verification evidence, limitations, and final human-approved claim

Debugging: Runtime Errors Are Not the Only Errors

40 min

Debugging: Runtime Errors Are Not the Only Errors

Learning goal: separate syntax/runtime errors from silent analytical errors.

"The code did not error" is often mistaken for "the analysis has no problem." But an analysis script can run completely cleanly while never filtering out draft or superseded rows, or while adding together values from different units (different metrics), or while a resubmitted record_id gets counted twice, producing a result that looks normal but is wrong. Python never flags this kind of error; only a person actively checking will catch it.

Runtime / Syntax Errors

  • The code cannot run; Python raises an error directly
  • Usually easy to notice, since execution stops
  • Common causes: a mistyped column name, a type mismatch, division by zero

Silent Analytical Errors

  • The code runs to completion with no error message at all
  • Only noticed when the result itself looks wrong, or someone independently re-verifies it
  • Common causes: not filtering by status, summing different unit metrics together, a duplicated record_id
Code that runs cleanly but produces a wrong answer
import pandas as pd

df = pd.read_csv("DS202_Analysis_Package_Practice.csv", parse_dates=["period"])

# Never filtered to status == "validated", and never grouped by unit first,
# so values from different metrics (count, hours, usd...) get summed together
summary = df.groupby("group")["value"].sum()
print(summary)
# The code never errors, but this sum has no business meaning
Ways to hunt for silent errors
MethodWhat it does
Row-count reconciliationDo the row counts before/after filtering and before/after groupby match expectations?
Manual spot-checkHand-calculate a small sample and compare it against the code's output
Edge-case inspectionDeliberately check how extreme values, missing values, or duplicate record_ids are handled
Sensitivity testingAdjust filter conditions or grouping and see whether the conclusion is fragile
Catching a silent error with row-count reconciliation

If there were 480 rows before filtering, there should be fewer than 480 after; if the row count after filtering is identical to before, the filter never took effect at all. This kind of simple row-count check often catches the problem faster than reading the code over again.

  • Do the row counts before and after filtering match what I expected?
  • Have I picked a small sample and hand-calculated it myself to compare?
  • How are extreme values, missing values, or a repeated record_id actually being handled?
  • If I switch to a different, equally reasonable filter or grouping, does the conclusion change completely?

Warning

"This code runs" and "this code computes the right answer" are two completely different things. Debugging an analysis cannot stop at checking for error messages: it also requires actively reconciling row counts, spot-checking samples, and testing edge cases.
Check yourself

An analysis script runs to completion with no errors or warnings. Does that mean the analysis result must be correct?

An analysis script runs to completion with no errors or warnings. Does that mean the analysis result must be correct?

Key takeaway: Completing the steps is not enough; the result must be verifiable, reproducible, and explainable.

Verification Ladder: Data → Code → Method → Claim

45 min

Verification Ladder: Data → Code → Method → Claim

Learning goal: verify source data, transformations, methods, outputs, and narrative claims in layers.

Verifying only "the number the code prints" is not enough, because an error can occur earlier or later in the chain: is the source data itself sound? Does the transformation logic have a bug? Is the chosen statistical method appropriate for this data? And finally, does the written claim from AI or a colleague overstate or over-assert what the code actually produced? The verification ladder splits verification into four layers, checked one at a time.

The four layers of the verification ladder
LayerWhat it verifiesThis dataset's example
DataThe source data's completeness, time coverage, and known limitationsDoes it cover the full period? Are sensitive_flag and source_version clearly defined?
CodeWhether the transformation, filter, and aggregation logic matches the analysis needWere the filter conditions actually applied? Are the groupby column and aggregation function correct?
MethodWhether the chosen statistical or analytical method fits this data and questionDoes a mean or a median better represent this group? Is the sample size large enough?
ClaimWhether the final written conclusion faithfully reflects the code output, without overreachingIs "Group A performs worst" just an observation for this period, not a general conclusion?
A Data-to-Code layer verification example
# Data layer: confirm the time coverage
df["period"].min(), df["period"].max()

# Code layer: confirm the filter actually took effect (keep only validated rows for one metric)
mask = (df["status"] == "validated") & (df["unit"] == "usd") & (~df["sensitive_flag"])
filtered = df[mask]
assert len(filtered) < len(df), "The filter may not have taken effect"

# Method layer: check whether the data is highly skewed, to decide if mean or median fits better
filtered.groupby("group")["value"].agg(["mean", "median", "std"])
An example of a Claim-layer gap

The code output is "Group A's average this month is slightly lower than the other groups, with a sample of only 8 rows," but the AI-written summary says "Group A clearly and persistently underperforms the other groups." The Code layer is completely correct; the problem sits at the Claim layer, where the written statement is far stronger than the evidence.

  • Data: is the underlying data itself complete? Are there known limitations?
  • Code: does the transformation and filter logic really do what I asked for?
  • Method: does this statistical method actually fit this data and this question?
  • Claim: does what was finally written overstate what the numbers themselves show?

Warning

A common failure mode: the Code layer gets checked carefully while Method and Claim are skipped entirely: the code is completely correct, but the wrong statistical method was chosen, or the final written conclusion sounds more certain and dramatic than the numbers actually show.
Check yourself

An AI-written summary says "Group A performs clearly and persistently below the other groups," but the code output only shows Group A's average was slightly lower for a single month, with a small sample size. Which layer of the verification ladder is the right place to catch this gap?

An AI-written summary says "Group A performs clearly and persistently below the other groups," but the code output only shows Group A's average was slightly lower for a single month, with a small sample size. Which layer of the verification ladder is the right place to catch this gap?

Key takeaway: Completing the steps is not enough; the result must be verifiable, reproducible, and explainable.

Reproducibility, Prompt Logs, and Provenance

35 min

Reproducibility, Prompt Logs, and Provenance

Learning goal: record environment, data version, prompts, generated code, edits, and outputs.

Three months later, a manager asks: "How was this conclusion actually computed?" Without a record, you may not even be able to reproduce your own analysis: which data version was used? What prompt was given to AI? Was the AI-generated code edited by hand afterward? Provenance means keeping this information so the analysis can be reproduced, traced, and understood by someone else looking at how the conclusion was reached.

Fields a Prompt / Code Provenance Log should record
FieldWhat to record
EnvironmentPython version, key package versions (such as pandas), and the run date
Data versionThe file name and source_version used (for example DS202_Analysis_Package_Clean.csv)
PromptThe full text of the prompt actually sent to AI
AI-generated codeAI's original code response
Manual editsWhat you changed in the AI-generated code, and why
Final outputThe final code version used, and the numbers or charts it produced
Record reproducibility information at the top of a notebook
import sys, pandas as pd

print("Python:", sys.version)
print("pandas:", pd.__version__)
print("Data version: DS202_Analysis_Package_Clean.csv")
print("Prompt summary: see provenance log row 3")
# Every subsequent edit to AI-generated code adds a new row to the log, with the reason for the change
What happens without provenance

Three months later someone asks "how was this number calculated," and it turns out nobody remembers which data version was used, what the prompt said, or whether the AI-generated code was edited by hand afterward. Redoing the analysis produces a different number from the original conclusion, and nobody can explain why.

  • Which version of the data file was used for this analysis?
  • What was the full text of the prompt actually sent to AI at the time?
  • Which parts of AI's original code were edited by hand, and why?
  • Which code version does the number that was finally used for a decision actually correspond to?

Warning

Without provenance, an analysis cannot be checked, reproduced, or handed off to someone else afterward, even if it was correct at the time. Especially when a conclusion feeds a consequential decision, "how was this number produced" must have a traceable record.
Check yourself

What is the main value of keeping a provenance log of prompts and AI-generated code?

What is the main value of keeping a provenance log of prompts and AI-generated code?

Key takeaway: Completing the steps is not enough; the result must be verifiable, reproducible, and explainable.

Privacy, Sensitive Data, and AI Governance

35 min

Privacy, Sensitive Data, and AI Governance

Learning goal: decide whether data may be sent to an AI service; minimize data; redact/synthesize when needed.

A colleague wants to paste the entire Analysis Package into an external AI tool so it can "see the full picture." But the dataset's sensitive_flag column marks certain rows as involving information that needs special handling, and those rows should never be sent to an external service without authorization. Before handing any data to AI, the first question is always: "Is this data allowed to leave its source system and be pasted into this tool?"

Steps for deciding whether to hand data to AI
StepWhat to confirm
Check authorization and policyHas this data been cleared for use with this AI tool? Does your institution's policy allow it?
Check sensitive_flagAre any rows flagged as needing special handling? Must they be excluded or handled separately?
Minimize the dataDoes this analysis actually need the full dataset, or only the aggregated statistics?
Redact or synthesizeCould de-identified columns, aggregated numbers, or synthetic data replace the raw detail records?
Minimize data before handing it to AI
# Wrong approach: paste the full detail dataset, including sensitive_flag rows, directly to an external AI tool

# Safer approach: exclude sensitive rows first, and share only aggregated statistics
safe = df[~df["sensitive_flag"]]
aggregate = safe.groupby("group")["value"].agg(["mean", "count"])
# Provide only the aggregated "aggregate" table to the AI tool, not the row-level raw detail
A situation that should trigger a pause

A colleague already has an external AI tool open and is about to paste in the entire Analysis Package, when they notice several rows have sensitive_flag true. This is the moment to pause before pasting and go back to confirm authorization and data minimization, rather than pasting first and asking questions later.

  • Has this data, for this purpose, actually been authorized for use with this AI tool?
  • Are there any rows with sensitive_flag true, and would they get pasted along with everything else?
  • Does this analysis actually need only aggregated statistics, rather than row-level detail?
  • Is there a de-identified or synthetic version of the data that could replace the raw detail?

Warning

"This AI tool is convenient" cannot replace the judgment of "is this data allowed to be sent here." Unless authorized, never paste confidential institutional data, personal data, or rows flagged as sensitive into an AI tool or an unapproved environment.
Check yourself

You want an external AI tool to help analyze data that includes rows where sensitive_flag is true. What is the most appropriate first step?

You want an external AI tool to help analyze data that includes rows where sensitive_flag is true. What is the most appropriate first step?

Key takeaway: Completing the steps is not enough; the result must be verifiable, reproducible, and explainable.

Independent Lab

55 min

Independent Lab: Auditable AI-Assisted Workflow

Learning goal: independently deliver analysis plus prompt log, code diff/review, verification evidence, limitations, and final human-approved claim.

Info

Practice task: using the practice data, independently choose an analysis question and walk the full course loop: Human Question → AI Proposal → Executable Analysis → Verification → Revision → Evidence, then deliver an auditable AI-Assisted Workflow + Verification Record. There is no published answer: your reasoning and verification are what get reviewed.
  1. Define the analysis question
    Write down the question you want to answer, the decision it supports, and the columns and definitions you will use.
  2. Ask AI to propose and generate code
    Use a structured prompt to have AI propose a method and implement it, keeping the full prompt and its raw output.
  3. Read before run and debug
    Check the code item by item before executing it, distinguishing syntax errors from possible silent analytical errors.
  4. Verify in layers
    Check the Data, Code, Method, and Claim layers of the verification ladder, leaving at least one concrete verification record per layer.
  5. Record provenance
    Complete a prompt/code provenance log recording environment, data version, prompt, AI output, and your edits.
  6. Confirm privacy and governance
    Check whether any rows have sensitive_flag true, and state how you handled them (excluded, aggregated, or de-identified).
  7. Deliver the final claim
    Write a bounded conclusion consistent with the evidence, and state who must approve it before use.
  • A clearly stated analysis question and the decision it supports
  • A complete prompt / code provenance log
  • At least one code review or diff (the gap between AI's raw output and your edited version)
  • At least one piece of verification evidence for each of the four verification-ladder layers
  • At least one limitation and one privacy/governance judgment (whether sensitive rows exist, and how they were handled)
  • A final claim with human approval, and a statement of the approver's role
An example of a deliverable that cannot be audited

A deliverable arrives with only a final conclusion and a chart attached: no prompt log, no layered verification record, and no statement of who approved the conclusion. A reviewer has no way to judge how the number was produced or to re-check any step, and can only send it back for the missing records.

  • Could someone else read my prompt log and understand what AI was actually asked to do?
  • Have I left at least one concrete piece of evidence for each of the Data, Code, Method, and Claim layers?
  • Have I honestly recorded which judgments still need approval from the business side or a supervisor?
  • If asked right now "how was this number produced," could I find the answer immediately?

Warning

"AI's proposal sounds reasonable" does not mean "this workflow is auditable." Without a prompt log, layered verification records, and a clear statement of human approval, this artifact cannot be audited or handed off.

Done

If AI helps write analysis code or draft the conclusion text, check every item yourself: was the prompt and context complete, did you actually read and understand the code, did verification cover all four layers from Data to Claim, and does the final claim honestly reflect limitations rather than overpromising. AI can speed up drafting; verification and final approval remain a human responsibility.

Key takeaway: Completing the steps is not enough; the result must be verifiable, reproducible, and explainable.

What next?