Shopify products carry two prices: product.price (what the customer pays) and (the original). When compare_at_price is higher, it's a sale.
Cheap themes check whether compare_at_price exists: {% if product.compare_at_price %}. Works until the sale ends and the merchant forgets to clear the field. Now the Sale badge stays up on full-price products.
The correct test is the actual price comparison:
{% if product.compare_at_price > product.price %}
<span class="badge badge--sale">Sale</span>
{% endif %}
AI tells: != blank or a bare compare_at_price check. Both pass on day one and fail after the next promo ends. Compare the prices, not the presence.