Skip to main content

Validation Layer Architecture

The ValidationLayer (monitoring/validation_layer.py) provides real-time data sanity checking on provider responses before metrics are exposed via the API.

Range Checks (FIELD_RANGES)

Every incoming numerical metric is validated against absolute domain boundaries:

Field NameMinimum AllowedMaximum AllowedUnit / Description
pe_ratio-500.02000.0Price to Earnings ratio
dividend_yield0.00.40Dividend yield (0% to 40%)
beta-5.010.0Market Beta
roe-5.05.0Return on Equity (-500% to +500%)
roa-5.05.0Return on Assets
market_cap1,000,00010,000,000,000,000Market Capitalization in local currency

Values falling outside these bounds are discarded and replaced with None.

Inter-Provider Consensus Check

When 2 or more providers supply a numerical value for the same field:

  1. The median value across all agreeing providers is computed: M = median(V_1, V_2, ..., V_k).
  2. For each provider value V_i, the absolute percentage deviation is calculated: deviation = |V_i - M| / M
  3. If deviation > VALIDATION_OUTLIER_THRESHOLD (default 0.50 or 50%), V_i is flagged as an outlier, logged in provider_health_log, and set to None.