The major bond rating agencies rate both municipal and corporate bonds on a scale from AAA (highest) down to D (in default). When comparing two muni bonds or two corporate bonds, the ratings will give you a relatively good sense of how safe they are. Two A rated corporate bonds are roughly equally safe. But that does not apply when choosing between a muni bond or a corporate bond. Generally municipal bonds are much safer, and in the event of a default, the recovery rate is usually much higher for a muni bond. Why is that?
Any government agency has a huge advantage over a corporation. They have a captive audience that they can tax to cover their debt. If Tesla (for example) gets in financial difficulty, they cannot make Wall Street lend them money. But Generaltown Alabama can raise taxes to cover their debt whether the general public likes it or not.
That doesn’t mean that municipal bonds are risk free. Puerto Rico municipal bonds for example, have defaulted on some of their debt payments. Nevertheless, all things equal, muni bonds are safer. Don’t assume that an A corporate is safer than a BBB muni bond, because it isn’t. Use the ratings to compare corporates to corporates and munis to munis, not against each other.