OpenBB-finance/OpenBB · error · ValueError
Unknown commodity: {commodity} -> Valid choices: {valid_choi
Error message
Unknown commodity: {commodity} -> Valid choices: {valid_choices} What it means
ValueError in the PSD query builder when the commodity string, normalized to lower snake_case (spaces and dashes to underscores), is not a key in the static COMMODITIES map. The map holds the USDA PSD commodity codes (e.g. 'cotton', 'oil_meal'); anything else is rejected before any request.
Source
Thrown at openbb_platform/providers/government_us/openbb_government_us/utils/psd_data_downloader.py:277
>>> get_timeseries('wheat', 'production', country='US, China, Brazil')
>>> get_timeseries('wheat', 'production, exports, ending_stocks') # Multiple attributes
>>> get_timeseries('wheat', ['production', 'exports']) # List of attributes
>>> get_timeseries('wheat', 'production', aggregate_region=True) # World + regions only
>>> get_timeseries('wheat') # ALL attributes for wheat
"""
# pylint: disable=import-outside-toplevel
import asyncio # noqa
from datetime import datetime
from aiohttp import ClientError, ClientSession
from openbb_core.app.model.abstract.error import OpenBBError
from openbb_core.provider.utils.helpers import get_async_requests_session, run_async
from pandas import DataFrame, notna
QUERY_URL = "https://apps.fas.usda.gov/PSDOnlineApi/api/query/RunQuery"
key = commodity.lower().replace(" ", "_").replace("-", "_")
if key not in COMMODITIES:
raise ValueError(
f"Unknown commodity: {commodity} -> Valid choices: {list(COMMODITIES.keys())}"
)
commodity_code = COMMODITIES[key]
valid_attrs = _get_commodity_attributes(commodity_code)
# Resolve attribute - None means ALL, can be single, list, or comma-separated
if attribute is None:
attr_ids = [ATTRIBUTES[a] for a in valid_attrs]
else:
# Normalize to list
if isinstance(attribute, str):
attr_list = [a.strip() for a in attribute.split(",") if a.strip()]
else:
attr_list = list(attribute)
# Validate each attribute
attr_ids = []
for attr in attr_list:View on GitHub (pinned to 3e071fcc2c)
Solutions
- Use one of the exact keys printed in the error's valid-choices list (case-insensitive, spaces/hyphens allowed).
- Expose COMMODITIES keys to your users as an enum/autocomplete instead of free text.
- Update the provider if USDA added a commodity the mapping lacks.
Example fix
# before get_psd_data(commodity="soy oil") # after get_psd_data(commodity="soybean_oil") # exact key from COMMODITIES
Defensive patterns
Strategy: validation
Validate before calling
from openbb_government_us.utils.psd_data_downloader import COMMODITIES
def normalize_commodity(c: str) -> str | None:
key = c.lower().replace(" ", "_").replace("-", "_")
return key if key in COMMODITIES else None Type guard
def is_valid_psd_commodity(c: str) -> bool is not None and isinstance(c, str) and c.lower().replace(" ", "_").replace("-", "_") in COMMODITIES Prevention
- Expose COMMODITIES keys as an enum/autocomplete instead of free text.
- Normalize user input to lower snake_case before calling.
When it happens
Trigger: Calling the PSD data function with a commodity name not in COMMODITIES: plurals ('oils' vs 'oil'), synonyms ('soybean oil' vs 'soybean_oil' if unmapped), or misspellings.
Common situations: Free-text user input passed through without normalization; commodity vocabulary drift between your app and the USDA PSD naming; casing/hyphen differences are handled, so failures are almost always wrong names.
Related errors
- Unknown attribute: '{attr}' for {commodity}. Valid attribute
- Attribute '{attr}' is not available for {commodity}. Valid a
- Country '{c}' is not available for {commodity}. Valid countr
- Incorrect email or password
- '{item}' is not available. Did you mean '{similar}'?
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/203e6c89d49caf47.
Report an issue: GitHub.