OpenBB-finance/OpenBB · error · ValueError

Industry must be one of {', '.join(industries)}

Error message

Industry must be one of {', '.join(industries)}

What it means

A Pydantic field_validator ValueError on FMPEquityScreenerQueryParams.industry: the industry string must either be 'all' or one of the literal values defined in the IndustryChoices enum. Any other free-text value is rejected client-side before the request.

Source

Thrown at openbb_platform/providers/fmp/openbb_fmp/models/equity_screener.py:162

    is_fund: bool | None = Field(
        default=None,
        description="If true, includes funds.",
    )
    all_share_classes: bool | None = Field(
        default=None,
        description="If true, includes all share classes of a equity.",
    )
    limit: int | None = Field(
        default=50000, description="Limit the number of results to return."
    )

    @field_validator("industry")
    @classmethod
    def _validate_industry(cls, v):
        """Validate industry."""
        industries = [v["value"] for v in IndustryChoices]
        if v and v not in industries + ["all"]:
            raise ValueError(f"Industry must be one of {', '.join(industries)}")
        return v

    @field_validator("country", mode="after")
    @classmethod
    def _validate_country(cls, v):
        """Validate country is supported by FMP."""
        if v is None:
            return v
        # Country stores alpha_2 in uppercase, FMP expects lowercase
        country_code = v.alpha_2.lower()
        valid_countries = list(Countries.__args__)
        if country_code not in valid_countries:
            raise ValueError(
                f"Country '{v.name}' ({v.alpha_2}) is not supported by FMP. "
                f"Valid options: {', '.join(sorted(valid_countries)[:20])}..."
            )
        return v

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Use exactly the enum values from openbb_fmp - inspect IndustryChoices (e.g. [v.value for v in IndustryChoices]) and pick the matching literal
  2. Use 'all' to skip industry filtering and post-filter client-side if your label has no equivalent
  3. Catch the pydantic ValidationError and re-present the allowed list to the user/UI

Example fix

# before
res = obb.screener.equity(provider='fmp', industry='Tech Software')  # ValueError

# after
from openbb_fmp.models.equity_screener import IndustryChoices
valid = [v.value for v in IndustryChoices]
industry = next((v for v in valid if 'software' in v.lower()), 'all')
res = obb.screener.equity(provider='fmp', industry=industry)
Defensive patterns

Strategy: validation

Validate before calling

from openbb_fmp.models.equity_screener import IndustryChoices
VALID_INDUSTRIES = {v.value for v in IndustryChoices} | {'all'}
industry = industry if industry in VALID_INDUSTRIES else 'all'

Type guard

def is_valid_fmp_industry(v: str) -> bool:
    from openbb_fmp.models.equity_screener import IndustryChoices
    return v == 'all' or v in {i.value for i in IndustryChoices}

Try / catch

from pydantic import ValidationError
try:
    res = obb.screener.equity(provider='fmp', industry=industry)
except ValidationError:
    res = obb.screener.equity(provider='fmp', industry='all')  # then filter client-side

Prevention

When it happens

Trigger: Calling obb.equity.screener(provider='fmp', industry='...') with a value not in IndustryChoices - e.g. 'Software Engineering' instead of 'Software', or a sector name like 'Technology' in the industry field.

Common situations: Passing human-readable or sector-level names where a specific industry literal is required, hardcoded industry lists drifting out of sync with the enum after package updates, casing/spacing mismatches ('real estate' vs 'Real Estate').

Related errors


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