When data fields can be missing, placeholder, or truly empty, never collapse them into the same falsy value. Explicitly represent and branch on “unknown vs empty” (or verified vs unverified), and avoid if x: checks that treat 0/""/None equivalently.
Apply these rules:
is None/is not None for optional numeric overrides and nullable fields so an explicit 0 is honored.counts_verified) or a distinct sentinel (None) instead of overloading 0 as both “unknown” and “empty”.null/missing fields by defaulting to "" only at the leaf (e.g., str(x.get(...) or "")).Example (verified vs placeholder count):
def payoff_tier(post):
eng = post.get("engagement") or {}
if eng.get("counts_verified"):
# real count: treat 0 as empty, >0 as non-empty
return 2 if (eng.get("num_comments") or 0) > 0 else 0
# unknown count (placeholder): don’t penalize as empty
return 1
# Optional numeric override: honor explicit 0
cap = config.get("_max_source_fetches")
if cap is not None:
cap = int(cap)