An asset check tests the data, not the code: no duplicate ids, no missing currency, amounts in range. Write it with @dg.asset_check(asset=transactions); a parameter named after the asset receives its stored value. Return dg.AssetCheckResult(passed=..., metadata={...}) and register it with Definitions(asset_checks=[...]).
When you materialize an asset, its checks run in the same run, and the asset page shows each check's latest result next to the materialization. You can also execute checks on their own, against what is already stored.
A failed check is ERROR by default. severity=dg.AssetCheckSeverity.WARN marks issues that deserve a look but are not wrong, such as a missing optional field. Put the evidence in metadata (how many duplicates, which ids) so the person who sees the red badge can act without rerunning anything. A check that raises an exception is not a failed check, it is a broken one: guard against empty data.
Fails, with the number of duplicates, when an id repeats.