Why it matters: AI coding assistants reproduce the visual syntax of a clean boundary, private fields, wrapper classes, sensible names, without protecting what that boundary is supposed to protect, so teams end up locked to vendors they thought they had abstracted away.
The Details:
Language models learn what encapsulation looks like from training data, not what it is for. Returning a database model straight from a repository method is one line; mapping it to a real domain type is thirty lines and several judgment calls about what callers should see. Nothing in the test suite or type checker punishes the shortcut, so the model takes it every time.
The leak is often fine. A throwaway script or an admin tool used by four people doesn't need a custom error type around a payment vendor; the wrapper would cost more than the risk it covers. The real question is how many callers depend on the thing and how likely the code behind it is to change, not whether some purity rule was followed.
The danger is the prototype that quietly becomes load-bearing with no one deciding to make it so. Nobody chose to put a SQLAlchemy model in an API response; it simply never got removed. A one-line comment flagging a shortcut as temporary, or a repo-level file telling the AI tool "the repository layer never returns ORM models," creates a visible tripwire before the shortcut calcifies.
A working test for any boundary: could you swap the database, vendor, or algorithm behind it without touching a single caller? If not, the wrapper is decoration, not protection, and that applies equally to AI-written code and human-written code.
Bottom Line: The fix isn't asking AI to write more cautious code; it's giving it a written, honest rule about what the boundary must hide before it writes anything at all.
Enjoy this article?
Listen to the Claude Code Conversations radio show or join the community.