Before a Contact is saved, make sure Last Name is not blank. Show a simple message when it is missing.
Write bulk-safe trigger logic and do not run SOQL or DML inside loops.