I’d place a small validation step between a local account adapter for 2Captcha and the dashboard database. Once an amount is parsed, it often gets trusted downstream. A nonfinite value can be accepted by a general-purpose numeric parser and then poison a sum, a chart range, or the comparison that triggers an operational alert.

Written with AI assistance. The Python example uses synthetic data and was checked locally.

Validate before applying business rules

Using Decimal preserves useful monetary precision but it still accepts inputs such as NaN and Infinity. Check the parsed value with is_finite() before attempting a range comparison. The rule in this fixture accepts finite decimals only. A separate business rule may apply a bound or forbid negative balances, depending on what the internal field represents.

The example starts with a synthetic adapter value. It makes no claim about values returned by the live account API. In a pipeline I’d keep an invalid-row count and the adapter’s run identifier, then retain the time of the last valid balance shown in the dashboard.

from decimal import Decimal, InvalidOperation def balance(raw): try: value = Decimal(raw) except InvalidOperation as error: raise ValueError("invalid decimal balance") from error if not value.is_finite(): raise ValueError("nonfinite balance") return value assert balance("0") == Decimal("0") assert balance("0.0001") == Decimal("0.0001") rejected = 0 for raw in ("NaN", "Infinity", "-Infinity", "bad"): try: balance(raw) except ValueError: rejected += 1 assert rejected == 4 print("Four malformed balance values rejected") 

The fixture prints Four malformed balance values rejected. The zero check guards against a common mistake where invalid or empty input is mapped to zero, which itself is a valid amount. I’d keep a separate test for a missing field if that is possible in the adapter’s input.

In a real test suite, feed this fixture through the same import call as an ordinary row and assert that it does not replace the previous balance. This connects parser correctness to the behavior the dashboard owner actually sees.

Further reading

Store JSON amounts with exact arithmetic.

Exercise a dashboard against its previous version.