Return error message instead of raising on unsupported indicators

When the LLM agent requests an indicator that isn't supported
(e.g. 'agt'), the function was raising a ValueError which crashed
the Market Analyst. Now it returns an error string that tells the
agent which indicators are available, allowing it to self-correct
and retry with a valid indicator.

Applied to both yfinance and alpha_vantage indicator functions.

Fixes #429
This commit is contained in:
Charlie Tonneslan 2026-03-23 09:41:40 -04:00
parent f362a160c3
commit 4aeaf09a2c
2 changed files with 10 additions and 4 deletions

View File

@ -58,8 +58,11 @@ def get_indicator(
}
if indicator not in supported_indicators:
raise ValueError(
f"Indicator {indicator} is not supported. Please choose from: {list(supported_indicators.keys())}"
supported = ", ".join(supported_indicators.keys())
return (
f"Error: Indicator '{indicator}' is not supported. "
f"Supported indicators: {supported}. "
f"Please retry with one of the supported indicators."
)
curr_date_dt = datetime.strptime(curr_date, "%Y-%m-%d")

View File

@ -129,8 +129,11 @@ def get_stock_stats_indicators_window(
}
if indicator not in best_ind_params:
raise ValueError(
f"Indicator {indicator} is not supported. Please choose from: {list(best_ind_params.keys())}"
supported = ", ".join(best_ind_params.keys())
return (
f"Error: Indicator '{indicator}' is not supported. "
f"Supported indicators: {supported}. "
f"Please retry with one of the supported indicators."
)
end_date = curr_date