If you're grid connected and see valid phase on the input for a certain amount of time of matching phase and measuring voltage you can provisionally connect at exactly that phase and voltage but without injecting power. After that you are allowed to slowly ramp up your output by leading the phase (while raising the voltage within certain limits) as long as you observe the effect that you have on the grid. If the grid phase drops away or there is any other anomaly (such as a voltage drop or rise of more than x V/s you are required to immediately disconnect, there are many other disconnect requirements but that's the main one with respect to line worker safety.
Three disconnects within a short period of time = no reconnect attempts for a much longer time. If the situation persists that's a failure and you are no longer allowed to connect to the grid until there has been an intervention and an inverter reset.
If your inverter is of the islanding variety then the rules are slightly different, then the transfer switch only gets energized when you match voltage and frequency but in the meantime the (usually battery backed up) inverter can supply local consumers.
By the time you come up with the idea of rolling your own inverter you have either become familiar with the requirements (which differ from region to region, and which in a properly designed inverter are mostly a matter of tweaking firmware parameters) or you will have to do so because you realize your responsibilities.
Anybody up for this kind of project will with a high degree of likelihood have the required knowledge because that knowledge is a lot simpler to acquire than the knowledge to build an inverter that isn't going to result in you being laughed out of the room when your EE buddies come look at your creation.
I would expect you to do a better job than 95% of the imported ones that I've taken apart and which all had massive shortcuts taken, good enough to pass first inspection and a year into warranty, not good enough for long term safe deployment. This ranges from unsuitable connectors, low quality inductors, even lower quality relays, undersized FET boards, insufficient cooling, bad cast aluminum housings, in general bad housings (not rodent and/or insect proof) and so on.