DEFAULT_MAX_LIMIT = 500 DEFAULT_MIN_LIMIT = 1 def bounded_limit(limit: int, max_limit: int = DEFAULT_MAX_LIMIT) -> int: """Clamp database query limits to a safe positive range.""" return max(DEFAULT_MIN_LIMIT, min(int(limit), max_limit)) def bounded_offset(offset: int) -> int: """Clamp pagination offsets to zero or above.""" return max(0, int(offset))