{"record":{"id":"9ce421c680312085","repo":"OpenBB-finance/OpenBB","slug":"value-must-be-an-int","errorCode":null,"errorMessage":"value must be an int","messagePattern":"value must be an int","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"openbb_platform/core/openbb_core/provider/abstract/data.py","lineNumber":20,"sourceCode":"\nfrom typing import Annotated\n\nfrom pydantic import (\n    AliasGenerator,\n    BaseModel,\n    BeforeValidator,\n    ConfigDict,\n    alias_generators,\n    model_validator,\n)\n\n\ndef check_int(v: int) -> int:\n    \"\"\"Check if the value is an int.\"\"\"\n    try:\n        return int(v)\n    except ValueError as exc:\n        raise TypeError(\"value must be an int\") from exc\n\n\nForceInt = Annotated[int, BeforeValidator(check_int)]\n\n\nclass Data(BaseModel):\n    \"\"\"\n    The OpenBB Standardized Data Model.\n\n    The `Data` class is a flexible Pydantic model designed to accommodate various data structures\n    for OpenBB's data processing pipeline as it's structured to support dynamic field definitions.\n\n    The model leverages Pydantic's powerful validation features to ensure data integrity while\n    providing the flexibility to handle extra fields that are not explicitly defined in the model's\n    schema. This makes the `Data` class ideal for working with datasets that may have varying\n    structures or come from heterogeneous sources.\n\n    Key Features:","sourceCodeStart":2,"sourceCodeEnd":38,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/core/openbb_core/provider/abstract/data.py#L2-L38","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Supply values coercible to int: 123, '123', or None where the field is optional","Pre-clean provider rows in the fetcher transform step (replace 'n/a'/'' with None, round/parse decimals)","Check the model's field type - if decimals are valid, the data belongs in a float field, not ForceInt"],"exampleFix":"# before\nrow = {'symbol': 'AAPL', 'volume': 'n/a'}\nmodel = Data(**row)  # TypeError: value must be an int\n\n# after\nrow = {'symbol': 'AAPL', 'volume': None}\nmodel = Data(**row)","handlingStrategy":"validation","validationCode":"def int_like(v) -> bool:\n    if v is None:\n        return True\n    try:\n        int(v)\n        return True\n    except (TypeError, ValueError):\n        return False","typeGuard":"def is_int_coercible(v) -> bool:\n    try:\n        int(v)\n        return True\n    except (TypeError, ValueError):\n        return False","tryCatchPattern":"from openbb_core.provider.abstract.data import Data\n\ntry:\n    row['volume'] = int(row['volume'])\n    model = Data(**row)\nexcept (TypeError, ValueError):\n    row['volume'] = None\n    model = Data(**row)","preventionTips":["Coerce numerics at ingestion: int(float(x)) for decimal strings","Map missing-value markers to None before building models","Unit-test provider transforms with dirty sample payloads"],"tags":["openbb","pydantic","type-coercion","int"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}