def remap_dict(src: dict, mapping: dict, keep_missed: bool = False) -> dict: """Remaps existing dict values to new keys.""" result = {} for key, val in src.items(): new_key = mapping.get(key) if new_key is not None: result[new_key] = val elif keep_missed: result[key] = val return result def safe_strip(value): if value is not None and hasattr(value, "strip"): return value.strip() return value