def validate_input(query): """Validate and clean user input""" if not query or not query.strip(): raise ValueError("Input cannot be empty") # Remove extra whitespace cleaned = query.strip() # Limit length to prevent abuse if len(cleaned) > 1000: raise ValueError("Input too long. Please limit to 1000 characters.") return cleaned