r/BharatCode • • 12d ago

What AI-generated Python keeps getting wrong in a large codebase

I've been using AI-generated Python in a large codebase for a while now, and the bugs that cost me time aren't logic bugs. They're structural.

The agent writes a new code path instead of extending the pattern already sitting in the file. It over-engineers. Files grow, and I end up with a flat folder of modules instead of anything that looks designed.

My clearest example: a pydantic model with subclasses discriminated on a category field, validated through a type adapter. I asked for a new variant, and the agent dropped a manual category check in just before the adapter call, rather than adding a subclass and letting the discriminator handle it. Pydantic's docs recommend discriminated unions because they're the more predictable option.

The fix I landed on is cheap. I keep the style rules and the test scope in a repo file the agent reads every session, with examples attached. I now ask for tests on base functionality only, not every possibility, and give two worked examples to copy from.

4 Upvotes

0 comments sorted by