{"record":{"id":"203e6c89d49caf47","repo":"OpenBB-finance/OpenBB","slug":"unknown-commodity-commodity-valid-choices","errorCode":null,"errorMessage":"Unknown commodity: {commodity} -> Valid choices: {valid_choices}","messagePattern":"Unknown commodity: (.+?) -> Valid choices: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/government_us/openbb_government_us/utils/psd_data_downloader.py","lineNumber":277,"sourceCode":"    >>> get_timeseries('wheat', 'production', country='US, China, Brazil')\n    >>> get_timeseries('wheat', 'production, exports, ending_stocks')  # Multiple attributes\n    >>> get_timeseries('wheat', ['production', 'exports'])  # List of attributes\n    >>> get_timeseries('wheat', 'production', aggregate_region=True)  # World + regions only\n    >>> get_timeseries('wheat')  # ALL attributes for wheat\n    \"\"\"\n    # pylint: disable=import-outside-toplevel\n    import asyncio  # noqa\n    from datetime import datetime\n    from aiohttp import ClientError, ClientSession\n    from openbb_core.app.model.abstract.error import OpenBBError\n    from openbb_core.provider.utils.helpers import get_async_requests_session, run_async\n    from pandas import DataFrame, notna\n\n    QUERY_URL = \"https://apps.fas.usda.gov/PSDOnlineApi/api/query/RunQuery\"\n    key = commodity.lower().replace(\" \", \"_\").replace(\"-\", \"_\")\n\n    if key not in COMMODITIES:\n        raise ValueError(\n            f\"Unknown commodity: {commodity} -> Valid choices: {list(COMMODITIES.keys())}\"\n        )\n\n    commodity_code = COMMODITIES[key]\n    valid_attrs = _get_commodity_attributes(commodity_code)\n    # Resolve attribute - None means ALL, can be single, list, or comma-separated\n    if attribute is None:\n        attr_ids = [ATTRIBUTES[a] for a in valid_attrs]\n    else:\n        # Normalize to list\n        if isinstance(attribute, str):\n            attr_list = [a.strip() for a in attribute.split(\",\") if a.strip()]\n        else:\n            attr_list = list(attribute)\n\n        # Validate each attribute\n        attr_ids = []\n        for attr in attr_list:","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/government_us/openbb_government_us/utils/psd_data_downloader.py#L259-L295","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nget_psd_data(commodity=\"soy oil\")\n\n# after\nget_psd_data(commodity=\"soybean_oil\")  # exact key from COMMODITIES","handlingStrategy":"validation","validationCode":"from openbb_government_us.utils.psd_data_downloader import COMMODITIES\n\ndef normalize_commodity(c: str) -> str | None:\n    key = c.lower().replace(\" \", \"_\").replace(\"-\", \"_\")\n    return key if key in COMMODITIES else None","typeGuard":"def is_valid_psd_commodity(c: str) -> bool is not None and isinstance(c, str) and c.lower().replace(\" \", \"_\").replace(\"-\", \"_\") in COMMODITIES","tryCatchPattern":null,"preventionTips":["Expose COMMODITIES keys as an enum/autocomplete instead of free text.","Normalize user input to lower snake_case before calling."],"tags":["validation","psd","commodity","enum"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}