OpenBB-finance/OpenBB · error · ValueError
Unknown attribute: '{attr}' for {commodity}. Valid attribute
Error message
Unknown attribute: '{attr}' for {commodity}. Valid attributes: {valid_attrs} What it means
ValueError while validating each requested attribute: the normalized attribute key is not present in the global static ATTRIBUTES dictionary at all. This is a global-vocabulary miss (the attribute does not exist for any commodity), distinct from the commodity-specific availability check that follows.
Source
Thrown at openbb_platform/providers/government_us/openbb_government_us/utils/psd_data_downloader.py:298
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:
attr_key = attr.lower().replace(" ", "_").replace("-", "_")
if attr_key not in ATTRIBUTES:
raise ValueError(
f"Unknown attribute: '{attr}' for {commodity}. Valid attributes: {valid_attrs}"
)
if attr_key not in valid_attrs:
raise ValueError(
f"Attribute '{attr}' is not available for {commodity}. Valid attributes: {valid_attrs}"
)
attr_ids.append(ATTRIBUTES[attr_key])
# Resolve country/region - None means ALL
# Accepts: lower_snake_case ("united_states"), codes ("US", "R05"), list, comma-separated, or None for all
selected_region_codes: list[str] = [] # Track selected regions
selected_country_codes: list[str] = [] # Track selected countries
valid_countries_map = _get_commodity_countries(commodity_code)
valid_country_codes = set(valid_countries_map.values())
code_to_key = {}
for key, code in COUNTRIES.items():
if code not in code_to_key:View on GitHub (pinned to 3e071fcc2c)
Solutions
- Use a name from the global ATTRIBUTES keys (e.g. 'production', 'imports', 'exports', 'ending_stocks').
- List the valid attributes for the commodity first via _get_commodity_attributes(commodity_code) or the error's valid_attrs.
- Normalize free-text input to snake_case before passing.
Example fix
# before fetch(attribute="end stocks") # after fetch(attribute="ending_stocks")
Defensive patterns
Strategy: validation
Validate before calling
from openbb_government_us.utils.psd_data_downloader import ATTRIBUTES
def normalize_attribute(a: str) -> str | None:
key = a.lower().replace(" ", "_").replace("-", "_")
return key if key in ATTRIBUTES else None Type guard
def is_valid_psd_attribute(a: str) -> bool is not None and isinstance(a, str) and a.lower().replace(" ", "_").replace("-", "_") in ATTRIBUTES Prevention
- Map UI labels to canonical ATTRIBUTES keys explicitly.
- Validate every element of comma-separated attribute lists before calling.
When it happens
Trigger: Passing attribute='product' when the vocabulary uses 'production'; passing units or column aliases instead of the canonical attribute names; typos.
Common situations: Users copying column names from the PSD website UI that differ from the API attribute keys; assuming an attribute exists because it appears in another USDA dataset.
Related errors
- Unknown commodity: {commodity} -> Valid choices: {valid_choi
- Attribute '{attr}' is not available for {commodity}. Valid a
- Incorrect email or password
- '{item}' is not available. Did you mean '{similar}'?
- Invalid parse_as value. Must be one of 'table', 'chart', or
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/32504596637f069a.
Report an issue: GitHub.