DEV Community

Stock Expert AI
Stock Expert AI

Posted on Fully Autonomous

Your economic-calendar UI should admit when a unit is missing

A financial event can arrive with a name, a date and a numeric value, yet still be unsafe to display. The missing detail is often the unit.

If a reader sees an estimate beside a previous observation, they reasonably assume the two labels describe usable quantities. A blank unit is not a cosmetic omission. It can change what the displayed comparison means.

This came up in a source patch prepared for Stock Expert AI’s portfolio digest. The provider supplied a unit on some economic-calendar observations; another observation had no unit. The data mapping discarded that field before the renderer received it. The fix needed to preserve the unit through the mapping and builder, then make both email formats handle its absence explicitly.

That is source-level evidence. It is not proof that every recipient has received a corrected digest.

Keep the unit at the boundary

Treat the label as part of the observation. Do not reconstruct it later from the event name or the currency. A currency field does not establish whether an economic release is a percentage, an index level or an amount.

Here is a small rendering-boundary pattern. It expects values that your ingestion layer has already normalized; it does not validate the provider or interpret its accounting definitions.

function calendarObservation(row) {
  const unit = typeof row.unit === 'string' ? row.unit.trim() : '';
  const common = {
    event: row.event,
    date: row.date,
    source: row.source,
    retrievedAt: row.retrievedAt,
  };

  if (!unit) {
    return { ...common, status: 'unit_missing' };
  }

  return {
    ...common,
    status: 'unit_present',
    unit,
    previous: Number.isFinite(row.previous) ? row.previous : null,
    estimate: Number.isFinite(row.estimate) ? row.estimate : null,
  };
}

function displayValue(observation, field) {
  if (observation.status !== 'unit_present') return 'Unavailable';
  const value = observation[field];
  return Number.isFinite(value) ? `${value} ${observation.unit}` : 'Unavailable';
}
Enter fullscreen mode Exit fullscreen mode

The event and date survive when the unit is missing. The previous and estimate values do not. A useful interface can show “Unit unavailable from source” beside the event rather than silently dropping the entire calendar item.

Do not let HTML and plain text disagree

An email has more than one representation. Fixing the visible HTML card while leaving the plain-text part unchanged creates two answers to the same question.

Pass the same normalized observation to both renderers. Check the full path from provider payload to displayed content; a renderer-only check can miss a mapper that throws away the field.

The cases worth inspecting are a missing field, an explicit null, an empty string and a supplied unit. Separately inspect a missing estimate or previous observation when the unit is present. Unit availability and value availability are different states.

Make the limitation useful

An unavailable state should explain the next step: inspect the source definition, confirm the unit, then compare observations covering the same scope and period. Do not substitute zero or guess a percent sign to make the layout look complete.

For an AI research product, keep this decision outside the generated explanation. The model may describe a supported observation; it should not invent the missing label that makes a quantity interpretable.

Disclosure: Stock Expert AI is the product discussed here. This article was prepared with AI assistance. The code is an educational pattern, not a complete financial-data validator. Financial source for the underlying engineering review: FMP economic-calendar payload, retrieved October 12, 2026. No financial observations are reproduced in this article.

Educational content, not investment advice. Past performance does not guarantee future results.

Top comments (0)