3.2: Reproducible AI-Assisted Analysis
Overview
Lesson 3.2: Reproducible AI-Assisted Analysis
This lesson teaches you how to design analysis workflows that are fully reproducible when AI systems are involved. You'll learn to document and version AI components (prompts, model versions), maintain complete logs of AI decisions and outputs, create reproducible computational environments (using containers and environment files), and structure code and workflows so that others can exactly replicate your analysis or modify it systematically.
Title
Lesson 3.2: Reproducible AI-Assisted Analysis
Purpose
This lesson teaches you how to design analysis workflows that are fully reproducible when AI systems are involved. You'll learn to document and version AI components (prompts, model versions), maintain complete logs of AI decisions and outputs, create reproducible computational environments (using containers and environment files), and structure code and workflows so that others can exactly replicate your analysis or modify it systematically.
The Reproducibility Challenge in AI-Assisted Research
Reproducibility, the ability of other researchers to independently repeat an analysis and obtain the same or closely consistent results, is a cornerstone of scientific validity. Without it, findings cannot be verified, errors cannot be caught, and results cannot be built upon with confidence. The reproducibility crisis of the past decade has focused attention on this requirement across disciplines, driving open data mandates, pre-registration norms, and rigorous statistical reporting standards.
AI-assisted analysis creates a new and in some ways more difficult reproducibility challenge. Traditional analysis pipelines, while complex, involve deterministic or statistically characterizable steps: read data, apply transformation, run statistical model, interpret output. Each step can be documented and replicated with sufficient detail. AI systems introduce elements that complicate this picture substantially.
First, AI systems may be non-deterministic. Even with the same inputs and the same model version, running the same prompt twice may produce different outputs if temperature is set above zero, a common default. Two researchers running identical prompts against the same data may obtain outputs that differ in phrasing, emphasis, or even content. What does reproducibility mean for an analysis component that is inherently variable?
Second, AI models are updated by vendors without necessarily providing explicit versioning controls to users. The 'same' model you used six months ago may behave differently today because its underlying weights or alignment training has changed. An analysis that could be reproduced by running the same prompt against the same data today may not be reproducible next year.
Third, AI systems depend on computational infrastructure, GPU hardware, software libraries, API endpoints, rate limits, that may change or become unavailable. A containerized traditional statistical analysis can often run unchanged for years; an AI analysis depending on a commercial API is subject to the vendor's continued support.
None of these challenges make AI research irreproducible in practice. They require researchers to think carefully about what reproducibility means in AI contexts and to take specific, proactive steps to achieve it.
Versioning AI Components: Prompts, Models, and Configurations
Version control is the practice of systematically tracking changes to documents or code over time, enabling you to see what changed, when, and why, and to restore any previous state. In software development, Git is the dominant version control system. In research, version control for code is increasingly standard. For AI-assisted analysis, version control must extend to the AI-specific components that determine outputs: prompts, model configurations, and any fine-tuned artifacts.
Prompt versioning is the practice of treating each distinct prompt version as a distinct artifact with a version label, a date, and a record of what changed and why. If you iterate through five prompt versions before settling on your final approach, each version should be recorded, ideally in a Git repository alongside your analysis code, so that the prompt development history is available alongside the code development history. The final prompt used for analysis should be clearly labeled as the authoritative version, and any commits after the confirmatory analysis should be clearly identified as post-hoc modifications.
Model versioning requires knowing exactly which model you used and locking your analysis to that version wherever possible. Different AI tools provide different levels of control here. Some commercial APIs allow you to specify the exact model version in your API call; others automatically route you to the latest version. Where exact version pinning is possible, do it. Where it is not, record the date of analysis and the version available at that date, and check whether the vendor has documented that version's behavior. For local or open-source models, pin model weights to a specific checkpoint and archive them or reference them through a content-addressed identifier (a hash of the model weights).
Configuration versioning means documenting all parameters that affect model behavior: temperature, maximum tokens, context window settings, system prompts, and any other settings available in your API or deployment. These should be stored as configuration files in your version control system, not as values hard-coded in scripts. A configuration file can be directly referenced and re-used, while values buried in code may be missed by someone attempting to reproduce your analysis.
For fine-tuned models, both the base model version and the fine-tuning procedure (data, hyperparameters, training duration, evaluation metrics) must be versioned. The fine-tuned weights themselves should be archived with a content-addressed identifier (their hash), and the fine-tuning code should be in version control. This creates a complete record that enables independent reproduction of the fine-tuning process.
Maintaining Complete Logs of AI Decisions and Outputs
Logging is the practice of recording what happened during an analysis run, inputs, intermediate states, decisions, and outputs, in a structured, persistent format. For traditional statistical analyses, logging might mean recording the software output from a model run in a lab notebook or appendix. For AI-assisted analyses, logging requires specific design because AI interactions are often transient by default: queries go to an API, responses come back, and nothing is automatically stored.
The first principle of AI logging is: never run an AI analysis without persisting the outputs. This sounds obvious, but researchers frequently run AI queries interactively in a session, iterating through prompts, seeing responses, forming interpretations, without systematically capturing what was returned. These ephemeral interactions represent lost provenance: the researcher made analytical decisions based on AI outputs that no longer exist and cannot be reviewed.
Structured logging for AI analysis should capture, for each AI interaction: the timestamp, the model and version, the full prompt submitted, the full response received, and any relevant context (which data record was being processed, which step in the pipeline). For batch analyses processing many records, this means creating a log database or structured log files that record the AI output for every record processed, not just a sample. Where log volume is a concern, logs can be compressed and archived while the summarized outputs used in the analysis are retained in the primary analysis dataset.
Outputs should be immutable once generated. A common mistake is to generate AI outputs, then modify them based on human review, then lose track of which parts were AI-generated and which were human-edited. A better practice is to maintain separate layers: the raw AI outputs (unchanged from the AI), the human review notes (what was checked and what the reviewer found), and the final analysis values (the outcome after any human correction, with the correction documented). This three-layer structure preserves the full provenance chain.
For quality assurance, logged outputs should be reviewed regularly, not just when a problem is suspected. Periodic audits of logged AI outputs against expected patterns can catch systematic errors or unexpected behavior changes early, before they propagate through your analysis.
Reproducible Computational Environments for AI Analysis
A computational environment is the combination of hardware, operating system, software libraries, and configuration settings in which an analysis runs. Traditional reproducibility infrastructure, conda environment files, pip requirements files, R DESCRIPTION files, captures the software layer of this environment, enabling other researchers to create an equivalent environment on their own hardware.
AI analysis creates additional environment dependencies that traditional environment files do not capture. GPU hardware and drivers affect the performance and sometimes the numerical behavior of AI computations. CUDA (the GPU computing platform) versions interact with deep learning library versions in ways that can affect model outputs for locally deployed models. Container technologies, Docker and Singularity/Apptainer in particular, provide the most complete environment capture, packaging not just software dependencies but the entire runtime environment.
For analyses using commercial API-based AI tools, the computational environment for the AI processing itself is on the vendor's side. You have limited control over it. What you can control is your own environment for: the code that constructs and sends queries, the code that processes and stores responses, and the validation and downstream analysis steps. These should be containerized or at minimum captured in environment files, ensuring that your code for interacting with the AI API can be reproduced even if the API behavior changes.
For analyses using locally deployed open-source AI models, full containerization is strongly recommended. A Docker image that contains the model weights, the inference code, and the analysis pipeline creates a complete, self-contained artifact that can in principle be re-run years later (assuming compatible hardware). This approach is particularly valuable for analyses central to published findings that may need to be verified or extended by other researchers.
Containerized environments should be deposited alongside the analysis code in a persistent repository. Not all repositories accept Docker images directly, but images can be pushed to Docker Hub or a registry with a tagged version that is cited in the paper, and the Dockerfile (the recipe for building the image) can be included in the code repository. Some repository systems (particularly for computational biology and data science) have developed specialized infrastructure for archiving containerized analyses.
Structuring AI Analysis Workflows for Reproducibility
A reproducible analysis workflow is one that, given the same inputs and environment, produces the same outputs, and whose steps are documented in enough detail that a knowledgeable researcher could re-implement it from scratch, achieving equivalent results. For AI-assisted analysis, this requires deliberate structural choices.
Separate development from production. Your prompt development phase, where you iterate, test, and refine, should be clearly separated from your confirmatory analysis phase. This separation should exist in your code and file organization: a development directory or branch for prompt iteration, a production directory or branch for the final analysis. The production analysis should run from a clean state using only the locked final prompt and configuration, with all development artifacts preserved in the development branch for transparency but clearly distinguished from the confirmed analysis.
Make the pipeline end-to-end runnable. A truly reproducible analysis can be re-run from raw inputs to final outputs by executing a single script or following a documented sequence of steps. For AI-assisted analyses, this means the pipeline must include all AI interaction steps, not just the downstream statistical steps that operate on already-generated AI outputs. If your pipeline starts from pre-computed AI outputs without the AI generation steps, it is only partially reproducible.
Seed random processes. Where AI outputs involve stochastic elements, temperature-based sampling, random seeds in local model inference, set and document random seeds to enable reproducible runs within a single model version. This does not solve the vendor-update reproducibility problem, but it enables within-session and short-term reproducibility.
Write validation into the pipeline. AI outputs should be validated as part of the pipeline, not as a separate manual step performed once and not documented. Pipeline-integrated validation might check: whether AI outputs are in expected format, whether confidence scores are within expected ranges, whether the distribution of output categories is consistent with baseline expectations, and whether a human-reviewed subset shows acceptable agreement. Pipeline-integrated validation creates a documented record of each analysis run's quality, enabling comparison across runs if behavior changes.
Version your outputs alongside your code. Use content-addressed storage (file hashes) to create immutable references to analysis outputs at each pipeline stage, enabling you to verify that a re-run produces identical outputs to the original analysis. This is particularly important for analyses that feed into downstream publications where exact numerical results must match.
Skill.re