GitHub Copilot Makes This Blazor Mistake All the Time
How form validation slowly ends up in the wrong place
Using GitHub Copilot while building forms in Blazor feels incredibly smooth, especially when validation rules seem to appear almost automatically as you type and everything works on the first run.
You add an input field, Copilot adds the validation, the UI shows the right error messages, and within minutes, you have a form that looks and feels complete.
That speed feels great, and it is very tempting to move on without thinking twice.
If you want to use Copilot the right way
Before we go deeper, a quick note.
I just released a new masterclass focused on using AI and GitHub Copilot for real .NET web development.
It is not about shortcuts or magic prompts.
It is about structure, clean code, and staying in control while moving fast.
…and use the code SUBSTACK for a discount.
Now let me explain why this matters.
When nothing breaks, structure slowly slips
From the outside, the form behaves perfectly fine.
The user cannot submit invalid data.
The messages show up at the right time.
There are no runtime errors.
But under the hood, something subtle starts to happen.
Validation logic creeps into Razor components, models end up defined inside code blocks, and rules that should live in one clear place get scattered across the UI.
None of this causes immediate pain, which is why it is so easy to miss.
Over time though, the form becomes harder to change, harder to test, and harder to reason about, even though it still looks simple on the surface.
A very small example already shows the issue
To make this concrete, I built a very small register form with an email field, a password field, and a confirm password field, so there is nothing complex or advanced going on.
After making sure everything worked, I asked GitHub Copilot to refactor the page.
At first glance, the result looked good, because the code was shorter, cleaner, and more organized than before.
But once I slowed down and really looked at what changed, it became clear that Copilot had made architectural decisions on my behalf, especially around where validation logic should live.
Those decisions were not necessarily wrong, but they were not decisions I consciously made.
Copilot is not careless, it is simply filling in gaps
This is the part that often gets misunderstood.
GitHub Copilot is not doing a bad job here, and it is not making random choices.
It is doing exactly what it is designed to do, which is to complete code based on patterns and examples it has seen before.
When you do not clearly tell Copilot how your application should be structured, it fills in the blanks using its own assumptions.
In other words, Copilot is not the architect unless you let it become one.
Clear rules change everything
The real fix is not about fighting AI or rejecting its suggestions.
The real fix is about giving Copilot clear guidance before it starts writing or refactoring code.
That means being explicit about where validation logic belongs, keeping Razor components focused on UI, using services, and relying on dependency injection as a default.
Once those expectations are clear, Copilot stops guessing and starts assisting in a much more helpful way.
You stay in control of the architecture, and Copilot becomes a powerful helper instead of a silent decision maker.
I walk through the full process in the video
I recorded a full video where I go through this example step by step and explain what is happening along the way.
You will see the original Blazor form, the refactor Copilot suggests, why parts of it look fine but cause issues later, and how to clean everything up properly.
If you already use GitHub Copilot, learning how to guide it properly will save you a lot of cleanup later and help you build apps you actually enjoy maintaining.
Take care
Patrick



