Skip to content

Reference

Errors

Mostly Right fails loudly when data is unavailable, temporally unsafe, or incompatible with a contract. Catch the four stable root exceptions for application control flow, then reach for a specialized subtype when you need a narrower recovery path.

import mostlyright as mr
try:
table = mr.weather.training_table("KNYC", from_date, to_date)
except mr.LeakageError:
# A row was not knowable by the decision cutoff.
...
except mr.ContractError:
# An input or output frame broke a documented contract.
...
except mr.NoDataError:
# No usable rows were available.
...
except mr.MostlyrightError:
# Any other structured SDK error.
...

MostlyrightError, LeakageError, ContractError, and NoDataError are available directly from mostlyright. Structured errors expose error_code, source, request_id, and a JSON-safe to_dict() payload when those fields apply.

TypeScript mirrors the same teaching families:

import {
ContractError,
LeakageError,
MostlyrightError,
NoDataError,
} from "mostlyright";

TypeScript errors expose errorCode, source, requestId, and toDict().

Import specialized Python exceptions from mostlyright.core.exceptions unless a domain documents a closer import path.

FamilyCommon membersRaised when
AvailabilityDataAvailabilityError, SourceUnavailableError, PayloadTooLargeErrorA source, date window, cache entry, or payload cannot be served
Live dataLiveStreamError, NoLiveDataError, NoCWOPDataErrorA live source has no fresh usable report
Temporal safetyLeakageError, OpenMeteoSeamlessLeakageError, TemporalDriftErrorData crosses a decision cutoff or two timelines disagree
ContractsContractError, SchemaValidationError, LabelAlignmentError, IssuedAtMissingError, UnitsContractErrorA frame, label, timestamp, or unit breaks its contract
ProvenanceSourceMismatchErrorResearch and live source identities do not match
ForecastsNWPError, NWPModelNotAvailableError, NWPModelRetiredError, GRIBIntegrityError, HistoricalDepthError, NoLiveForNWPError, StormNotFoundErrorA forecast model or requested depth is unavailable or invalid
SatelliteSatelliteError, GOESS3Error, GOESDataCorruptError, ProductNotRegisteredError, StationOutOfGridErrorA satellite product, object, or station projection fails
Economy and financeIndicatorNotYetReleasedError, EarningsError, EarningsFactCorruptError, CaptureNotAvailableError, KalshiCountRuleViolationErrorA release or earnings artifact is not yet available or fails validation

weather.live.latest() raises NoLiveDataError instead of returning an old report as if it were current.

import asyncio
from mostlyright import weather
from mostlyright.core.exceptions import NoLiveDataError
try:
report = asyncio.run(weather.live.latest("KNYC"))
except NoLiveDataError as error:
print(error.source)
print(error.to_dict())

This is a normal operational branch. Retry according to your policy, switch to another active station, or stop the live decision. Do not silently substitute archived or stale data.

DataAvailabilityError adds a stable reason value and an operator-facing hint. The reason enum is shared across Python and TypeScript:

  • model_unavailable
  • out_of_window
  • cache_miss
  • source_404
  • source_5xx
  • rate_limited

Branch on reason, not message text.

TherminalError was renamed to HttpError in 2.0. The HTTP family also includes NotFoundError, RateLimitError, ValidationError, AuthenticationError, ForbiddenError, and ServerError.

Polymarket settlement can raise PolymarketEventError, PolymarketSettlementError, PolymarketStrikeError, or TooEarlyToSettleError.

KalshiTickerError is intentionally a ValueError, not a MostlyrightError, because a malformed ticker is caller input:

from mostlyright.markets.kalshi import KalshiTickerError, parse_ticker
try:
parsed = parse_ticker(user_supplied_ticker)
except KalshiTickerError:
...