def _fetch_keyspaces(self, keyspace_list: Optional[List[str]] = None) -> List[str]:
        """
        Fetches a list of keyspace names from the Cassandra database. The list can be
        filtered by a provided list of keyspace names or by excluding predefined
        keyspaces.

        Parameters
        ----------
        - keyspace_list (Optional[List[str]]): A list of keyspace names to specifically
        include. If provided and not empty, the method returns only the keyspaces
        present in this list. If not provided or empty, the method returns all
        keyspaces except those specified in the _exclude_keyspaces attribute.

        Returns
        -------
        - List[str]: A list of keyspace names according to the filtering criteria.

        """
        all_keyspaces = self.run(
            "SELECT keyspace_name FROM system_schema.keyspaces", fetch="all"
        )

        # Type check to ensure 'all_keyspaces' is a sequence of dictionaries
        if not isinstance(all_keyspaces, Sequence):
            raise TypeError("Expected a sequence of dictionaries from 'run' method.")

        # Filtering keyspaces based on 'keyspace_list' and '_exclude_keyspaces'
        filtered_keyspaces = []
        for ks in all_keyspaces:
            if not isinstance(ks, Dict):
                continue  # Skip if the row is not a dictionary.

            keyspace_name = ks["keyspace_name"]
            if keyspace_list and keyspace_name in keyspace_list:
                filtered_keyspaces.append(keyspace_name)
            elif not keyspace_list and keyspace_name not in self._exclude_keyspaces:
                filtered_keyspaces.append(keyspace_name)

        return filtered_keyspaces

        Fetches a list of keyspace names from the Cassandra database. The list can be
        filtered by a provided list of keyspace names or by excluding predefined
        keyspaces.

        Parameters
        ----------
        - keyspace_list (Optional[List[str]]): A list of keyspace names to specifically
        include. If provided and not empty, the method returns only the keyspaces
        present in this list. If not provided or empty, the method returns all
        keyspaces except those specified in the _exclude_keyspaces attribute.

        Returns
        -------
        - List[str]: A list of keyspace names according to the filtering criteria.

        
llama-index-integrations/tools/llama-index-tools-cassandra/llama_index/tools/cassandra/cassandra_database_wrapper.py