code: def _clean_label(s: Optional[str], is_key: bool) -> str:
      """Processes the string into the sanitized format required by AI platform
      labels.
  
      https://cloud.google.com/ml-engine/docs/resource-labels
  
      """
      if s is None:
          return ""
  
      # periods are not allowed by AI Platform labels, but often occur in,
      # e.g., learning rates
      DECIMAL_REPLACEMENT = "_"
      s = s.replace(".", DECIMAL_REPLACEMENT)
  
      # lowercase, letters, - and _ are valid, so strip the leading dashes, make
      # everything lowercase and then kill any remaining unallowed characters.
      cleaned = re.sub(r"[^a-z0-9_-]", "", s.lower()).lstrip("-")
  
      # Keys must start with a letter. If is_key is set and the cleaned version
      # starts with something else, append `k`.
      if is_key and cleaned != "" and not cleaned[0].isalpha():
          cleaned = "k" + cleaned
  
      return _truncate(cleaned, AI_PLATFORM_MAX_LABEL_LENGTH)
  
file_path: caliban/caliban/platform/cloud/util.py
imports: import re
  from typing import Dict, List, Optional, Tuple, Union
  import caliban.util
  import caliban.util.argparse
label_desc: Use image node_id 2 for calling a global function with example usage: _clean_label(s, is_key) and returns: _truncate, str