When the ability to run spatial queries is mission critical (for example, in a web application), it's wise to put a CHECK constraint on a geometry column. This will ensure that no invalid geometries will make their way into the database, so users won't be surprised by a failing query. On the other hand, an INSERT or UPDATE query with invalid geometry will fail, so this has to be correctly handled.
The constraint is created after all geometries are made valid (or no geometries have been inserted yet), using a query like this:
ALTER TABLE planet_osm_polygon ADD CONSTRAINT enforce_validity CHECK (ST_IsValid(way));