Never trust client input
Every incoming WebSocket message is hostile until proven otherwise. Validate the envelope, the type, every field, the lengths. Pydantic gives you structured validation with one decorator and one schema, with errors you can return as {type: 'error', code: 'validation_error', message: ...}.
Tagged union with Literal
Define a Pydantic model per message type and use Field(discriminator='type') to dispatch. The framework picks the right model based on the type field, validates the rest, and returns a typed object. Bad messages reject before any handler runs.