OpenBB-finance/OpenBB · error · OpenBBError
Invalid chokepoint name: {chokepoint}. Expected one of {list
Error message
Invalid chokepoint name: {chokepoint}. Expected one of {list(CHOKEPOINTS_NAME_TO_ID.keys())}. What it means
Second-layer validation in the chokepoint volume fetcher: while mapping user tokens to ids, a token that is neither a CHOKEPOINTS_NAME_TO_ID key, a value, nor a 'chokepoint'-prefixed string raises here. It complements the Pydantic validator by also rejecting strings like 'chokepoint99' that merely start with 'chokepoint' but pass the earlier isinstance checks (e.g. list inputs bypass strict name checking in the validator).
Source
Thrown at openbb_platform/providers/imf/openbb_imf/models/maritime_chokepoint_volume.py:324
async def get_one(chokepoint_id):
"""Get data for a single chokepoint."""
data = await get_daily_chokepoint_data(
chokepoint_id, query.start_date, query.end_date
)
if data:
results.extend(data)
# Accept both keys and values from CHOKEPOINTS_NAME_TO_ID
chokepoint_ids: list = []
for chokepoint in chokepoints:
if chokepoint in CHOKEPOINTS_NAME_TO_ID:
chokepoint_ids.append(CHOKEPOINTS_NAME_TO_ID[chokepoint])
elif chokepoint in CHOKEPOINTS_NAME_TO_ID.values() or chokepoint.startswith(
"chokepoint"
):
chokepoint_ids.append(chokepoint)
else:
raise OpenBBError(
f"Invalid chokepoint name: {chokepoint}. Expected one of {list(CHOKEPOINTS_NAME_TO_ID.keys())}."
)
tasks = [
get_one(chokepoint_id) for chokepoint_id in chokepoint_ids if chokepoint_id
]
task_results = await asyncio.gather(*tasks, return_exceptions=True)
for task_result in task_results:
if isinstance(task_result, Exception):
raise OpenBBError(task_result)
if not results:
raise OpenBBError("The response was returned empty with no error message.")
return results
View on GitHub (pinned to 3e071fcc2c)
Solutions
- Sanitize every token against CHOKEPOINTS_NAME_TO_ID keys/values before building the query.
- Use only documented chokepointN ids with N in 1..24.
- Prefer comma-separated validated strings over raw lists so the field validator runs.
Example fix
# before maritime_chokepoint_volume(chokepoint=['Strait of Hormuz', 'chokepoint99']) # after maritime_chokepoint_volume(chokepoint=['Strait of Hormuz', 'chokepoint7'])
Defensive patterns
Strategy: validation
Validate before calling
import re
from openbb_imf.models.maritime_chokepoint_volume import CHOKEPOINTS_NAME_TO_ID
VALID = set(CHOKEPOINTS_NAME_TO_ID) | set(CHOKEPOINTS_NAME_TO_ID.values())
def clean(tokens):
ok = []
for t in tokens:
t = t.strip()
if t in VALID or re.fullmatch(r'chokepoint([1-9]|1[0-9]|2[0-4])', t):
ok.append(t)
else:
raise ValueError(f'unknown chokepoint: {t}')
return ok Type guard
import re
def is_valid_chokepoint_token(t: str) -> bool:
return (t in CHOKEPOINTS_NAME_TO_ID
or t in CHOKEPOINTS_NAME_TO_ID.values()
or re.fullmatch(r'chokepoint([1-9]|1[0-9]|2[0-4])', t) is not None) Prevention
- Never pass unsanitized user strings as chokepoint lists
- Regex-validate chokepointN ids against 1..24
When it happens
Trigger: Passing a list of chokepoints containing an unknown token (lists are filtered, not validated, upstream); or a comma string that slipped through with a 'chokepointX' style value not in the map (any 'chokepoint'-prefixed string is accepted downstream, then fails in the actual fetch); or values that bypass field validation.
Common situations: Programmatic list inputs built from user data without sanitization; passing 'chokepoint25' or arbitrary 'chokepoint<text>' strings; direct QueryParams construction skipping validators.
Related errors
- Invalid chokepoint name: {chokepoint} -> Expected one of {li
- Invalid chokepoint name: {v} -> Expected one of {list(CHOKEP
- Invalid chokepoint value: {v} -> Expected a string or a list
- port_code must be a string or a list of strings.
- Invalid port_code: {item}. Must be a valid port ID or name.A
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/4ab1129227abd577.
Report an issue: GitHub.