{"record":{"id":"0c358564afd1f9f7","repo":"OpenBB-finance/OpenBB","slug":"unknown-country-region-c-for-commodity-val","errorCode":null,"errorMessage":"Unknown country/region: '{c}' for {commodity}. Valid countries: {valid_keys}. Valid regions: {valid_regions}","messagePattern":"Unknown country/region: '(.+?)' for (.+?)\\. Valid countries: (.+?)\\. Valid regions: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/government_us/openbb_government_us/utils/psd_data_downloader.py","lineNumber":385,"sourceCode":"                country_codes.append(code)\n            # Check if it's a country name (snake_case)\n            elif country_key in COUNTRIES:\n                code = COUNTRIES[country_key]\n                # Validate against commodity-specific countries\n                if valid_country_codes and code not in valid_country_codes:\n                    valid_keys = get_valid_country_keys()\n                    raise ValueError(\n                        f\"Country '{c}' is not available for {commodity}. Valid countries: {valid_keys}\"\n                    )\n                selected_country_codes.append(code)\n                country_codes.append(code)\n            else:\n                # Unknown country/region\n                valid_keys = sorted(\n                    [k.lower().replace(\" \", \"_\") for k in valid_countries_map]\n                )\n                valid_regions = list(REGIONS.keys())\n                raise ValueError(\n                    f\"Unknown country/region: '{c}' for {commodity}. \"\n                    + f\"Valid countries: {valid_keys}. Valid regions: {valid_regions}\"\n                )\n\n    # If aggregate_region is True, expand appropriately\n    if aggregate_region:\n        if \"R00\" in selected_region_codes:\n            # \"world\" selected - fetch all regional aggregates + any specific countries\n            country_codes = (\n                list(REGIONS.values()) + selected_country_codes\n            )  # R00, R01, ... R18 + specific countries\n            country_codes = list(set(country_codes))  # Dedupe\n        elif selected_region_codes:\n            # Specific regions selected - add World + those regions + any countries\n            country_codes = [\"R00\"] + selected_region_codes + selected_country_codes\n            country_codes = list(set(country_codes))  # Dedupe\n        elif selected_country_codes:\n            # Only countries selected - add World + their regions","sourceCodeStart":367,"sourceCodeEnd":403,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/government_us/openbb_government_us/utils/psd_data_downloader.py#L367-L403","documentation":"The fallback branch when the input matches neither an ISO code (COUNTRY_TO_REGION), a known region, the 'eu' shorthand, nor a COUNTRIES name key. It reports both the commodity's valid countries (snake_cased) and the global REGIONS keys, since the value could be intended as either.","triggerScenarios":"Typos ('unitd_states'), country names not in the map (alternative spellings, former names), or region names passed in the wrong form (e.g. 'Sub-Saharan Africa' instead of its R-code).","commonSituations":"Free-text country input; non-English or alternate romanizations; stale maps missing newly recognized countries.","solutions":["Use an exact key from the error's valid countries list or a valid region code (R00..R18 / 'world').","Normalize input to lower snake_case before calling.","Update the provider if a legitimately named country is missing from COUNTRIES."],"exampleFix":"# before\nfetch(commodity=\"cotton\", country=\"Unitd States\")\n\n# after\nfetch(commodity=\"cotton\", country=\"united_states\")","handlingStrategy":"validation","validationCode":"from openbb_government_us.utils.psd_data_downloader import COUNTRIES, COUNTRY_TO_REGION, REGIONS\n\ndef classify_country_input(c: str) -> str | None:\n    key = c.lower().replace(\" \", \"_\")\n    if key in (\"eu\",): return \"region\"\n    if key in REGIONS or key.upper() in REGIONS: return \"region\"\n    if c.upper() in COUNTRY_TO_REGION: return \"code\"\n    if key in COUNTRIES: return \"name\"\n    return None  # will raise 'Unknown country/region'","typeGuard":"def is_recognized_country_or_region(c: str) -> bool is not None and isinstance(c, str) and classify_country_input(c) is not None","tryCatchPattern":null,"preventionTips":["Normalize to lower snake_case and check against COUNTRIES/REGIONS before calling.","Suggest close matches when user input fails recognition (fuzzy match over valid keys)."],"tags":["validation","psd","country","region"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}