OpenBB-finance/OpenBB · error · TypeError

value must be an int

Error message

value must be an int

What it means

TypeError from check_int, the BeforeValidator backing the ForceInt annotated type used across OpenBB's standard data models (prices, volumes, dates-as-ints, etc.). It attempts int(v); if the value cannot be coerced (e.g. 'abc', '', None handling aside), it raises this TypeError so Pydantic surfaces a clean message instead of a confusing coercion error.

Source

Thrown at openbb_platform/core/openbb_core/provider/abstract/data.py:20

from typing import Annotated

from pydantic import (
    AliasGenerator,
    BaseModel,
    BeforeValidator,
    ConfigDict,
    alias_generators,
    model_validator,
)


def check_int(v: int) -> int:
    """Check if the value is an int."""
    try:
        return int(v)
    except ValueError as exc:
        raise TypeError("value must be an int") from exc


ForceInt = Annotated[int, BeforeValidator(check_int)]


class Data(BaseModel):
    """
    The OpenBB Standardized Data Model.

    The `Data` class is a flexible Pydantic model designed to accommodate various data structures
    for OpenBB's data processing pipeline as it's structured to support dynamic field definitions.

    The model leverages Pydantic's powerful validation features to ensure data integrity while
    providing the flexibility to handle extra fields that are not explicitly defined in the model's
    schema. This makes the `Data` class ideal for working with datasets that may have varying
    structures or come from heterogeneous sources.

    Key Features:

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Supply values coercible to int: 123, '123', or None where the field is optional
  2. Pre-clean provider rows in the fetcher transform step (replace 'n/a'/'' with None, round/parse decimals)
  3. Check the model's field type - if decimals are valid, the data belongs in a float field, not ForceInt

Example fix

# before
row = {'symbol': 'AAPL', 'volume': 'n/a'}
model = Data(**row)  # TypeError: value must be an int

# after
row = {'symbol': 'AAPL', 'volume': None}
model = Data(**row)
Defensive patterns

Strategy: validation

Validate before calling

def int_like(v) -> bool:
    if v is None:
        return True
    try:
        int(v)
        return True
    except (TypeError, ValueError):
        return False

Type guard

def is_int_coercible(v) -> bool:
    try:
        int(v)
        return True
    except (TypeError, ValueError):
        return False

Try / catch

from openbb_core.provider.abstract.data import Data

try:
    row['volume'] = int(row['volume'])
    model = Data(**row)
except (TypeError, ValueError):
    row['volume'] = None
    model = Data(**row)

Prevention

When it happens

Trigger: Provider data or user input feeding a ForceInt field with a non-numeric string: {'volume': 'n/a'}, {'date': 'not-a-number'}; float strings like '1.5' also fail because int('1.5') raises ValueError; happens during Data model construction (fetch result validation) or QueryParams validation.

Common situations: Provider API responses with placeholder text in numeric fields; empty strings for missing numerics; decimal strings where the schema declares an int; hand-crafted dicts/tests using wrong literal types.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/9ce421c680312085. Report an issue: GitHub.