"""Markers for Data Card fields that have no value.""" from typing import Any # The sources were read, but none of them states this value. NOT_REPORTED = "not_reported" # The field does not apply to this model, e.g. tokenization for an image model. NOT_APPLICABLE = "not_applicable" # No value was extracted: the source or the LLM call failed, or the field was # never filled. NOT_RETRIEVED = "not_retrieved" MISSING_MARKERS = (NOT_REPORTED, NOT_APPLICABLE, NOT_RETRIEVED) # Older Data Cards use "N/A" and similar strings for every missing value. LEGACY_MISSING = {"", "n/a", "na", "none", "null", "unknown", "not available"} MISSING_VALUES = LEGACY_MISSING | set(MISSING_MARKERS) def is_missing(value: Any) -> bool: """True for None, empty containers, legacy empty strings, and the markers.""" if value is None: return True if isinstance(value, (list, dict)): return not value return isinstance(value, str) and value.strip().lower() in MISSING_VALUES def is_legacy_missing(value: Any) -> bool: return isinstance(value, str) and value.strip().lower() in LEGACY_MISSING