{"record":{"id":"16d44f31983ef69d","repo":"TauricResearch/TradingAgents","slug":"llm-max-retries-must-be-an-integer-not-a-boolean","errorCode":null,"errorMessage":"llm_max_retries must be an integer, not a boolean: {value!r}","messagePattern":"llm_max_retries must be an integer, not a boolean: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"tradingagents/graph/trading_graph.py","lineNumber":55,"sourceCode":"from .checkpointer import checkpoint_step, clear_checkpoint, get_checkpointer, thread_id\nfrom .conditional_logic import ConditionalLogic\nfrom .propagation import Propagator\nfrom .reflection import Reflector\nfrom .setup import GraphSetup\nfrom .signal_processing import SignalProcessor\n\nlogger = logging.getLogger(__name__)\n\n\ndef _coerce_max_retries(value):\n    \"\"\"Validate an ``llm_max_retries`` value to a non-negative int.\n\n    Accepts an int or a numeric string (env vars arrive as strings). Rejects\n    booleans and negatives loudly so a misconfiguration fails at startup rather\n    than silently disabling retries.\n    \"\"\"\n    if isinstance(value, bool):\n        raise ValueError(f\"llm_max_retries must be an integer, not a boolean: {value!r}\")\n    try:\n        n = int(value)\n    except (TypeError, ValueError) as exc:\n        raise ValueError(f\"llm_max_retries must be an integer, got {value!r}\") from exc\n    if n < 0:\n        raise ValueError(f\"llm_max_retries must be >= 0, got {n}\")\n    return n\n\n\nclass TradingAgentsGraph:\n    \"\"\"Main class that orchestrates the trading agents framework.\"\"\"\n\n    def __init__(\n        self,\n        selected_analysts=(\"market\", \"social\", \"news\", \"fundamentals\"),\n        debug=False,\n        config: dict[str, Any] = None,\n        callbacks: list | None = None,","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/TauricResearch/TradingAgents/blob/a33fd4c0f134485a43553a2c23a63cb14adbd88f/tradingagents/graph/trading_graph.py#L37-L73","documentation":"ValueError raised by _coerce_max_retries (tradingagents/graph/trading_graph.py) when the llm_max_retries value is a bool. In Python, bool is a subclass of int, so True would silently coerce to 1 retry — the explicit isinstance(value, bool) check rejects it so a misconfiguration like llm_max_retries=True fails at startup rather than half-working.","triggerScenarios":"Passing llm_max_retries=True or False to TradingAgentsGraph, or setting a TRADINGAGENTS_* env var / config value that a previous layer converted to a boolean. The bool check fires before int() conversion.","commonSituations":"Config templating that turns numeric strings into booleans ('1' -> True); YAML files where `llm_max_retries: true` is accepted as a bool; users intending 'on/off' semantics for a count parameter.","solutions":["Set llm_max_retries to a non-negative integer, e.g. 3 (or the string '3' from env vars).","Fix YAML/JSON config files that define the value as true/false.","Audit any config preprocessing that coerces values to bool before they reach the graph."],"exampleFix":"# before\nTradingAgentsGraph(config={**DEFAULT_CONFIG, 'llm_max_retries': True})\n\n# after\nTradingAgentsGraph(config={**DEFAULT_CONFIG, 'llm_max_retries': 3})","handlingStrategy":"type-guard","validationCode":"def is_valid_max_retries(value) -> bool:\n    return not isinstance(value, bool) and isinstance(value, (int, str)) and str(value).lstrip('-').isdigit()","typeGuard":"def isNonNegativeIntLike(value: unknown): value is number | string {\n  return (typeof value === 'number' || typeof value === 'string')\n    && /^\\d+$/.test(String(value).trim());\n}","tryCatchPattern":"try:\n    graph = TradingAgentsGraph(config=config)\nexcept ValueError as e:\n    if 'llm_max_retries' in str(e):\n        config['llm_max_retries'] = 3\n        graph = TradingAgentsGraph(config=config)\n    else:\n        raise","preventionTips":["Never write true/false for retry counts in YAML/JSON config.","Watch for config templating that coerces '1' strings into booleans.","Validate config dicts with a schema (e.g. pydantic) before graph construction."],"tags":["configuration","validation","retries","startup"],"backgroundTag":null,"analyzedSha":"a33fd4c0f134485a43553a2c23a63cb14adbd88f","analyzedAt":"2026-08-14T19:45:16.920Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}