OpenBB-finance/OpenBB · error · OpenBBError

Invalid chokepoint value: {v} -> Expected a string or a list

Error message

Invalid chokepoint value: {v} -> Expected a string or a list of strings from {list(CHOKEPOINTS_NAME_TO_ID)}. - or chokepointN, where N is a number between 1 and 24

What it means

Terminal branch of the `chokepoint` field validator reached when the value is neither a string, a list, nor falsy — i.e. an int, dict, or other type. Note that a list of unknown strings does NOT raise here: it is silently filtered to known names, so this error is purely about the Python type of the input.

Source

Thrown at openbb_platform/providers/imf/openbb_imf/models/maritime_chokepoint_volume.py:100

            return (
                v
                if v in CHOKEPOINTS_NAME_TO_ID
                or v in list(CHOKEPOINTS_NAME_TO_ID.values())
                else None
            )

        if isinstance(v, list):
            chokepoints = []
            for d in v:
                if d in CHOKEPOINTS_NAME_TO_ID:
                    chokepoints.append(CHOKEPOINTS_NAME_TO_ID[d])
                elif d in list(CHOKEPOINTS_NAME_TO_ID.values()):
                    chokepoints.append(d)

            return ",".join(chokepoints) if chokepoints else None

        raise OpenBBError(
            ValueError(
                f"Invalid chokepoint value: {v} -> "
                f"Expected a string or a list of strings from {list(CHOKEPOINTS_NAME_TO_ID)}."
                " - or chokepointN, where N is a number between 1 and 24"
            )
        )


class ImfMaritimeChokePointVolumeData(MaritimeChokePointVolumeData):
    """IMF Maritime Chokepoint Volume Data.

    Source: https://portwatch.imf.org/datasets/42132aa4e2fc4d41bdaf9a445f688931/about
    """

    model_config = ConfigDict(
        extra="ignore",
        validate_by_alias=True,
        validate_by_name=True,

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Pass a string name, a 'chokepointN' string id, a comma-separated string, or a list of strings.
  2. Convert numeric ids to 'chokepoint{N}' strings before calling.
  3. Coerce untrusted input with str() and validate against the known names first.

Example fix

# before
maritime_chokepoint_volume(chokepoint=7)

# after
maritime_chokepoint_volume(chokepoint='chokepoint7')
Defensive patterns

Strategy: type-guard

Validate before calling

if not isinstance(chokepoint, (str, list)) or not all(isinstance(x, str) for x in ([chokepoint] if isinstance(chokepoint, str) else chokepoint)):
    chokepoint = str(chokepoint)  # or reject

Type guard

def is_chokepoint_input(v) -> bool:
    if isinstance(v, str):
        return True
    return isinstance(v, list) and all(isinstance(x, str) for x in v)

Prevention

When it happens

Trigger: Passing `chokepoint=7` (bare int id), `chokepoint={'id': 7}`, or another non-string/list type. Strings and lists fall into earlier branches; anything else reaches this raise.

Common situations: Assuming the numeric chokepoint id can be passed as an integer (it must be the string 'chokepoint7'); passing a dict from an upstream config; pandas/numpy scalar types leaking in.

Related errors


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