# Taming My AI Assistant's Code Formatting Habits

> Source: <https://dev.to/nexus_labs_eaac0473959e4d/taming-my-ai-assistants-code-formatting-habits-3ogp>
> Published: 2026-10-03 14:00:34+00:00

Man, I love my AI coding assistant. Seriously, it’s a game-changer for speeding up boilerplate, brainstorming complex logic, and even just getting unstuck. But for the longest time, there was this one nagging friction point that almost made me throw my mechanical keyboard across the room: its code formatting.

Every single time, without fail, any code snippet it suggested would come out in generic, by-the-book PEP8. Which, fine, is a good default. But *our* team? We run a slightly opinionated black setup. We like a line-length = 90 instead of the default 88, we pin target-version = ['py310'], and we even skip-string-normalization = true for some specific reasons. So, while my AI would dutifully churn out beautiful, functional Python, my ruff linter would immediately light up like a Christmas tree, complaining about line breaks and string quotes. It was a constant battle, and honestly, a productivity killer. I was spending a good 10-15 minutes every single day just reformatting code it suggested.

My first attempts were, predictably, naive. I’d try things like, "Okay, generate a function, but make sure it uses *our* style." The assistant would usually just shrug (metaphorically, of course) and give me standard PEP8. Not helpful.

Then I tried being more explicit. I’d paste a small chunk of *our* codebase and say, "Match this style for the next suggestion." This worked… sometimes. For that *one* suggestion. The moment I moved onto a new request, it was back to square one. It was like teaching a dog a new trick, only for it to forget it five minutes later.

I even attempted to list out the rules: "Use 2 spaces for indentation, line length 90, no double quotes for strings." This got incredibly tedious. I’d inevitably forget a rule or two, and for more complex formatting decisions (like how black handles dictionary comprehensions or long argument lists), just listing rules wasn't granular enough. The AI would often interpret "line length 90" differently than black would.

I knew the AI *could* understand formatting tools because if I prompted it with "format this snippet as if black was run," it would often do a decent job. But it was always black's *default* settings, not *our specific config*.

The breakthrough, as these things often are, was surprisingly simple once I stumbled upon it. My AI assistant, whether it's Copilot X or a custom GPT I'm poking at, needs *context*. It needs to *see* the rules, not just be told about them in vague terms.

What if I just… gave it our actual black config?

So, I crafted a standard preamble that I now prepend to any substantial code generation request. It looks something like this:

The difference was almost instantaneous. Suddenly, the code suggestions weren't just syntactically correct, they were *stylistically* correct according to our internal rules. Lines broke at 90 characters, string literal quotes matched our preferences, and overall, it just *felt* like code I’d written myself, or that a teammate would write.

It’s not 100% perfect, mind you. Sometimes a truly bizarre edge case will pop up where it deviates slightly. But we're talking about maybe a 95% hit rate now. That 10-15 minutes of daily reformatting? Gone. It’s now down to literally a minute or two *per week* of minor tweaks, if that.

This isn't just about saving time; it's about reducing cognitive load. I no longer have to mentally context-switch between "what the AI generated" and "what our linter expects." The suggestions integrate seamlessly into my workflow, which is exactly what an AI assistant should do.

If your AI assistant is causing formatting headaches, try giving it the actual configuration files or snippets of your style guide. It turns out, these models are pretty good at pattern matching when you give them the right patterns to match against. My developer life just got a whole lot smoother.
