With its IP67 rating, an AirTag can survive contact with water in a lot of situations. It should be fine if it's out in the rain for a while or if you drop your keys in a shallow puddle. Apple's advice for other liquid spills applies here too: If you get juice, tea or soda on an AirTag, you should rinse it with tap water. Never open a wet AirTag, as this can damage the circuitry. If your AirTag gets wet, dry it off with a soft cloth, then you can open it, take the battery out, and let it air dry in case any liquid got inside. If it doesn't work once it's fully dry and you put it back together, try replacing the battery.
Be aware that water resistance is not a static quality. For one, IP rating tests are done in perfect scenarios with still water, which doesn't reflect accidents in reality. Immersing an AirTag into a machine crafted for the evaluation is not the same as accidentally running it through a washing machine, for instance. An AirTag might still work after going through a wash cycle, though factors like hot water and detergent are hard on it.
Similarly, the seals Apple applies to AirTags are not permanent. Over time, these can weaken from natural wear and tear, even if you take good care of the tracker. An AirTag you've had for three years won't resist liquids as well as one you just took out of the box.
It's wise to view the resistance rating as a backup if something happens, not as something you should actively put to the test. Don't hook an AirTag on something you plan to take underwater, and keep them away from fast-moving water like ocean waves or river rapids. Avoid steam from showers or saunas, as heat, water vapor and condensation are not good for electronics.