{"record":{"id":"6e9fa2483d48b123","repo":"TauricResearch/TradingAgents","slug":"invalid-value-for-env-var-exc","errorCode":null,"errorMessage":"Invalid value for {env_var}: {exc}","messagePattern":"Invalid value for (.+?): (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tradingagents/default_config.py","lineNumber":67,"sourceCode":"            f\"expected a boolean ({'/'.join(_BOOL_TRUE + _BOOL_FALSE)}), got {value!r}\"\n        )\n    if isinstance(reference, int) and not isinstance(reference, bool):\n        return int(value)\n    if isinstance(reference, float):\n        return float(value)\n    return value\n\n\ndef _apply_env_overrides(config: dict) -> dict:\n    \"\"\"Apply TRADINGAGENTS_* env vars to the config dict in-place.\"\"\"\n    for env_var, key in _ENV_OVERRIDES.items():\n        raw = os.environ.get(env_var)\n        if raw is None or raw == \"\":\n            continue\n        try:\n            config[key] = _coerce(raw, config.get(key))\n        except ValueError as exc:\n            raise ValueError(f\"Invalid value for {env_var}: {exc}\") from exc\n    return config\n\n\nDEFAULT_CONFIG = _apply_env_overrides({\n    \"project_dir\": os.path.abspath(os.path.join(os.path.dirname(__file__), \".\")),\n    \"results_dir\": os.getenv(\"TRADINGAGENTS_RESULTS_DIR\", os.path.join(_TRADINGAGENTS_HOME, \"logs\")),\n    \"data_cache_dir\": os.getenv(\"TRADINGAGENTS_CACHE_DIR\", os.path.join(_TRADINGAGENTS_HOME, \"cache\")),\n    \"memory_log_path\": os.getenv(\"TRADINGAGENTS_MEMORY_LOG_PATH\", os.path.join(_TRADINGAGENTS_HOME, \"memory\", \"trading_memory.md\")),\n    # Optional cap on the number of resolved memory log entries. When set,\n    # the oldest resolved entries are pruned once this limit is exceeded.\n    # Pending entries are never pruned. None disables rotation entirely.\n    \"memory_log_max_entries\": None,\n    # LLM settings\n    \"llm_provider\": \"openai\",\n    \"deep_think_llm\": \"gpt-5.5\",\n    \"quick_think_llm\": \"gpt-5.4-mini\",\n    # When None, each provider's client falls back to its own default endpoint\n    # (api.openai.com for OpenAI, generativelanguage.googleapis.com for Gemini, ...).","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/TauricResearch/TradingAgents/blob/a33fd4c0f134485a43553a2c23a63cb14adbd88f/tradingagents/default_config.py#L49-L85","documentation":"ValueError raised by _apply_env_overrides (tradingagents/default_config.py) as a wrapper around the inner coercion failure: it names exactly which TRADINGAGENTS_* env var could not be parsed. It fires at import time when DEFAULT_CONFIG is built, so a bad env var prevents the process from starting — by design, so unattended runs never run with silently wrong settings.","triggerScenarios":"Any TRADINGAGENTS_* env var listed in _ENV_OVERRIDES whose value cannot be coerced to the type of the existing default: a non-'true'/'false' string for a bool key (inner error 28), or a non-numeric string like 'abc' for an int/float key. Empty values are skipped, so the var must be non-empty.","commonSituations":"Deployments with stale .env files after config keys changed type; CI variables carrying whitespace/quotes; secrets managers injecting unexpected formats like 'true ' or \"'true'\".","solutions":["Read the message: it names the env var and the underlying reason — fix that variable's value.","Strip quotes/whitespace from values in your .env or secret manager.","Run a quick startup smoke test (import tradingagents.default_config) in CI to catch env problems before deploy."],"exampleFix":"# before\nTRADINGAGENTS_LLM_API_SPACE=abc   # int-typed key\n\n# after\nTRADINGAGENTS_LLM_API_SPACE=8     # numeric value matching the default's type","handlingStrategy":"validation","validationCode":"import os\n\n_BOOL_KEYS = {'debug', 'quick_think_llm_anthropic'}  # adapt to _ENV_OVERRIDES bool keys\n\ndef env_overrides_look_valid(env_overrides: dict[str, str]) -> list[str]:\n    problems = []\n    for env_var, key in env_overrides.items():\n        raw = os.environ.get(env_var)\n        if raw and key in _BOOL_KEYS and raw.strip().lower() not in {'true', 'false'}:\n            problems.append(f'{env_var}={raw!r} not a boolean')\n    return problems","typeGuard":null,"tryCatchPattern":"try:\n    import tradingagents.default_config\nexcept ValueError as e:\n    # message names the env var and cause; fail the deployment\n    raise SystemExit(f'bad TRADINGAGENTS_* env var: {e}')","preventionTips":["Run a startup env audit in CI that imports the config module.","Keep .env values free of quotes and stray whitespace.","After upgrading the package, diff the accepted config keys and types."],"tags":["configuration","environment-variables","startup","validation"],"backgroundTag":null,"analyzedSha":"a33fd4c0f134485a43553a2c23a63cb14adbd88f","analyzedAt":"2026-08-14T19:45:16.920Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}