There are too many factors that change between games for there to be a general theory that really matters, but in my experience, the rules most groups tend to follow include:
1.) Don't step on toes. If someone is playing an arcane spellcaster, most groups won't add a second if there is another option. However, what constitutes stepping on toes is subjective. A wizaard and a sorcerer may be seen as stepping on each other's toes, while an archer Gloomstalker Ranger and a Two Handed Melee Gloomstalker Ranger may not.
2.) Have a healer. This isn't really necessary anymore, but most groups want it.
3.) Have a front line. Most groups of 3 or more PCs look to have at least 2 PCs with durability.
4.) Have a sneaky PC. Again, not really necessary in 5E, but I've heard a lot of people ask if there is a rogue before selecting their class.
5.) Have a face. In the 5E era, I hear more people ask about who is oing to be the leader/face/negotiator in the party.
One PC may fill multiple of these roles. A dex based paladin can be 2 through 5 all by themself, for example.
These rules have different weight in different games. If you're hacking and slashing through a Megadungeon, PCs may have less need of a face. If you have a bunch of arcane spellcasters, stealth PCs may not be necessary for opening locks or hiding.
While most groups do not consider the following, they're things I consider when parties are being formed and I may lean into filling these gaps if not already filled:
1.) Do we have someone that can use magic to gather information (augury, arcane eye, divination, etc...)?
2.) Do we have a ritual spellcaster that can detect magic, identify, and tiny hut?
3.) Do we have a controller that can stop enemies (sleep, banishment, hold monster, etc...)?
4.) Do we have a storyline interwoven backstory to help the DM align the group to the adventure?
5.) Do we have comic relief / chaos?
[Edit] 6.) Do we have a sage with high intelligence skills or other access to lore and information?