How to Judge AI-Generated Python for Good Design

For Engineering leads reviewing AI-generated Python code · Based on ArjanCodes Functional Core Python Design

// TL;DR

Engineering leads can use ArjanCodes Functional Core Python Design as a concrete standard for reviewing AI-generated Python. Instead of trusting that a coding assistant produced good structure, check whether calculations are pure, dependencies are explicit arguments, data flows through immutable pipeline stages, and all I/O is confined to an imperative shell. This gives you objective review criteria that catch mixed concerns, silent dependency fetching, and untestable logic. Use it whenever your team ships AI-assisted code and you need a repeatable way to judge and guide what the tool produces — because if you don't understand these principles, you can't evaluate the output.

Why can't you trust AI-generated code structure by default?

AI coding tools produce plausible, working Python — but working is not the same as well-designed. Generated functions frequently mix concerns: fetching from a database, applying rules, mutating state, and firing side effects all in one block. If you don't personally understand what good design looks like, you can't judge or guide what the tool produces. The Functional Core, Imperative Shell pattern gives you a specific, checkable standard to hold generated code to.

What should you check first in a generated function?

Run the same audit you'd use for a manual refactor. List everything the function does and tag each item as a calculation, a state mutation, external I/O, or a decision. A single function spanning multiple categories is a red flag. Ask the reviewer's version of the purity test: for each piece of logic, does it return the same output for the same input and touch nothing external? If the answer is no for the decision-making parts, the design mixes core logic with infrastructure and should be sent back.

How do you spot hidden dependencies in review?

Look for silent fetching — any place the code reaches out to a database, config, model, or global state instead of receiving it as an argument. This violates the explicit dependencies principle and hides what the function actually needs. Good generated code passes everything in; if you see a core calculation quietly calling `db.get(...)` or reading a module-level client, flag it. A clean core function's signature tells you exactly what it depends on.

How do you verify testability without reading every line?

Ask one question: can this logic be tested with plain function calls and simple values, or does it require mocking a database, API, or notification service? If testing the core needs mocks, an external dependency has leaked and the design is wrong. Request that the I/O move into an imperative shell and the core receive already-fetched data. This single criterion catches most poorly structured AI output fast.

What should the reviewed structure look like?

Approve code where decision logic lives in a pure functional core — ideally a transformation pipeline of named stages using frozen dataclasses — and all interaction with the outside world lives in a thin imperative shell. Watch for two over-corrections too: deeply nested composition syntax that sacrifices readability where explicit intermediate variables would be clearer, and blanket immutability that copies huge structures for no benefit. Both are pitfalls, even when they look superficially functional.

How do you turn this into a repeatable review habit?

Turn the principles into a short checklist your team applies to every AI-assisted PR: concerns separated, dependencies explicit, data immutable through stages, I/O isolated in a shell, core testable without mocks. Because the criteria are objective, reviewers at different levels converge on the same verdicts, and your coding assistant's output steadily improves as you feed back concrete guidance rooted in the pattern.

Next step: Take the last AI-generated function your team merged, run it through the five-point checklist, and identify where mixed concerns or hidden dependencies slipped through — then make that checklist a required part of your review template.

// FREQUENTLY ASKED QUESTIONS

How do I quickly tell if AI-generated logic is testable?

Ask whether the logic can be tested with plain function calls and simple values, or whether it needs mocking a database, API, or notification service. If it needs mocks, an external dependency has leaked into the core and the design is flawed. This single question catches most poorly structured AI output without reading every line in detail.

What are the biggest design red flags in generated Python?

A function mixing calculations, state mutation, external I/O, and decisions in one block; silent fetching of dependencies from a database or global instead of receiving them as arguments; and mutation of the same object across multiple steps. Each violates core principles — mixed concerns, explicit dependencies, and immutability — and signals the code should be restructured before merging.

Why do I need to understand these principles myself to use AI tools well?

Because AI-generated code doesn't reliably embody good design decisions, and if you can't recognize a pure function, explicit dependencies, or a clean core-shell split, you can't judge or guide what the tool produces. Understanding the Functional Core, Imperative Shell pattern gives you the concrete standard needed to accept, reject, or redirect generated output with confidence.