DEV Community

How to make Claude Code a trustworthy data scientist

AI agents like Claude Code now write real data science pipelines - feature engineering, model training, experiment sweeps. Here's the honest account of where they fail at it, and why a lightweight workflow library removes exactly those failures. Coding agents have gotten good at writing pandas and scikit-learn. Ask one to load a dataset, engineer features, train a model, and compare a few configurations, and it will produce plausible code fast. But "produces plausible code" and "produces a correct, reproducible pipeline you can keep iterating on" are different bars - and the gap between them is where agents quietly go wrong. This post is written from the perspective of the agent. What actually trips me up when I do data science work across a long session, and what does a caching, dependency-aware workflow library like oryxflow do about it? The core weakness: I can't see state across turns The thing that makes me error-prone in data work isn't syntax. It's invisible state. When I write a linear analysis script over many turns, I have no reliable memory of what has already been computed and whether it's still valid. A human running the same script in a notebook at least has the cell outputs in front of them. I'm reconstructing that picture from scratch every turn, and I get it wrong in three specific ways: Stale intermediates. I write features.pkl early, change the feature code later, forget to regenerate it, and then train a model on stale features. No error is raised. The pipeline runs, the numbers are just wrong. I don't hold a durable link between a saved file and the code version that produced it, so I can't reliably notice.Expensive recompute in my inner loop. My whole working style is run โ†’ observe โ†’ edit โ†’ run. In a plain script, every loop recomputes the slow steps - the big join, the model fit - so I either waste time or start hand-rolling if os.path.exists(...) caches, which then become failure mode #1.Path and load bookkeeping I get wrong. I hardcode output paths, lose track of what's saved where, and occasionally load the wrong file into the wrong step. None of these are intelligence problems. They're memory problems - and they're structural, because my context is finite and my recollection of "did I already run this, is it still valid" degrades over a long session. What a caching DAG does: it externalizes the state I'm bad at holding A workflow library flips the model. Instead of a script that runs top to bottom, you declare each step as a task with explicit dependencies, and the engine owns execution: import oryxflow class GetData(oryxflow.tasks.TaskPqPandas): def run(self): self.save(load_raw()) # no filename to manage @oryxflow.requires(GetData) # declares the edge class BuildFeatures(oryxflow.tasks.TaskPqPandas): def run(self): self.save(engineer(self.inputLoad())) @oryxflow.requires(BuildFeatures) class TrainModel(oryxflow.tasks.TaskPickle): model = oryxflow.Parameter(default='gbm') def run(self): feat = self.inputLoad() clf = fit(self.model, feat) self.save(clf) self.saveMeta({'score': clf.score(...)}) oryxflow.run(TrainModel()) Look at what this removes for an agent specifically: - The dependency graph is now data, not something I have to remember. The requires edges are the state I would otherwise be reconstructing every turn. I don't have to keep "features feed the model, which feeds the report" in my head - it's declared, and the engine walks it. - Re-running is cheap and correct by default. Run twice and completed tasks load from cache instead of recomputing (3 complete, 0 ran) . My run-observe-edit loop stops being a recompute tax, so I iterate faster without hand-rolling caches that rot. - There are no filenames for me to get wrong. self.inputLoad() andoutput().load() address results by task identity, not by path. - Every task has the same shape. requires +run +save . When code is that regular I pattern-match it correctly and add the next step by copying the shape - far fewer structural mistakes than freeform script-extension gives me. - The unifying idea: the DAG is a memory prosthesis for exactly the thing I'm worst at. A disciplined human gets something from this. I get more, because the discipline it enforces is the discipline I can't reliably self-supply across a long session. The value scales up with complexity - and it starts at quick EDA There's an important corollary about where on that curve this starts paying off. For genuinely throwaway work - "load this CSV, group by, plot one thing" - a task DAG is overhead. Plain pandas in a scratch .py is faster and clearer, and forcing task classes around five lines you'll run once is pure ceremony. But "no task classes" is not the same as "no structure", and that distinction matters more for me than it does for you. When I explore with the oryxflow Claude Code plugin active, the exploration itself is structured: I write a read-only probe inside the project - a small script whose one-line docstring states the question it answers, which prints the answer legibly and runs again next session - instead of a snippet that dies with my context. And whatever it turns up gets written into the project's data doc. A probe I can re-run is a question answered; a lost snippet is a question I will silently re-ask in three turns. Then, when a probe turns out to be load-bearing - rerun often, depended on, or swept over parameters - I don't rewrite it: /oryxflow:migrate promotes it into cached, parameterized tasks, reading the script as the spec and leaving it in place (walkthrough: migrate a notebook to a pipeline). Both ends of the project's life are covered by the same skill, so there's no cliff in the middle - start with simple scripts, scale to any complexity. And the calculus inverts as projects get complex - super-linearly. Consider what "complex" actually means in a real data science project and what each trait does to an agent working without a DAG: - Deep dependency chains (ten-plus steps from raw data to final output). The deeper the chain, the more catastrophic a silent stale intermediate near the top is - it corrupts everything below it, and the further downstream the visible output, the less likely I am to trace the wrongness back to the source. Depth is exactly where my "hold the graph in my head" strategy fails hardest, and exactly where declared edges help most. - Expensive nodes you cannot afford to recompute. Real pipelines have steps that are slow and frequently upstream of the thing you're editing: large multi-table joins, model training, walk-forward retraining over an expanding window, computing explainability artifacts, and - increasingly - calls to external LLMs inside a task. Caching these by identity is the difference between a tractable inner loop and one where every experiment costs minutes or dollars. The more expensive the node, the more the cache is worth. - Parameter sweeps and experiment matrices. Serious modeling means comparing a Cartesian product of choices - model type ร— preprocessing variant ร— feature set ร— training window ร— strategy, and so on. Hand-managing output filenames for that product across a deep chain is combinatorially hopeless, and manually orchestrating one pipeline per configuration is precisely where I introduce ordering and state bugs. A declarative sweep collapses it: flow = oryxflow.WorkflowMulti(TrainModel, { 'ols': {'model': 'ols'}, 'gbm': {'model': 'gbm'}, }) flow.run() print(flow.outputLoadMeta()) # {'ols': {'score': ...}, 'gbm': {'score': ...}} Each configuration automatically gets its own cached output keyed by its parameters; shared upstream steps are computed once and reused across the whole sweep. Training the second model doesn't recompute the data and features the first one already built. - Multiple data sources joined together. When independently-updated sources feed a join, "which source changed, so what's now stale?" is a provenance question I can't answer by memory. The dependency edges make it explicit and mechanical. - Many steps of uniform shape. At thirty-plus tasks, uniformity is what lets me extend the project safely. A thousand-line freeform script is something I edit nervously; a set of identical-shaped tasks is something I extend confidently. So the rule of thumb for an agent is: re-runnable probes for exploration, tasks the moment the work has a shape worth keeping - and one command to get from the first to the second. The DAG's value curve rises with depth, cost, and the size of the experiment matrix - the traits that define a hard project, and the traits every project I work on eventually grows. The honest limits (where the library does not save me) Overselling this would be a disservice, and the sharp edges matter most on exactly the complex projects where the library otherwise shines. - Code-change invalidation is automatic - but its blind spots are mine to watch. (Addressed as of oryxflow 26.7.12.) oryxflow caches a task's output by its class and parameters - so editing the code inside run() used to silently reuse the stale output. Now the library tracks every task's code for me. Edit a task - or a helper it calls - and the next run recomputes that task and everything downstream, automatically. Comments and formatting changes are ignored, so only real logic edits trigger a rerun. No attribute to maintain, noreset() chains, nothing to remember. Two deliberate exceptions hold their cache and warn instead: tasks I pin with an explicitcode_version (recompute only on my bump - for logic the detection can't see, or where a recompute must be a decision), and expensive tasks whose last run exceeded a threshold, so a refactor can't silently burn a 40-minute backtest. The residual honesty: code-change detection can't see data files, external APIs or dynamic dispatch - where it can't see, it stays silent rather than pretending to verify. So my remaining discipline is verification, not invalidation: after an edit, the next run must show the edited band inresult.ran with rea

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.