{"record":{"id":"336d19af71621f35","repo":"assafelovic/gpt-researcher","slug":"cannot-convert-env-value-to-list","errorCode":null,"errorMessage":"Cannot convert {env_value} to list","messagePattern":"Cannot convert (.+?) to list","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"gpt_researcher/config/config.py","lineNumber":293,"sourceCode":"                except ValueError:\n                    continue\n            raise ValueError(f\"Cannot convert {env_value} to any of {args}\")\n\n        if type_hint is bool:\n            return env_value.lower() in (\"true\", \"1\", \"yes\", \"on\")\n        elif type_hint is int:\n            return int(env_value)\n        elif type_hint is float:\n            return float(env_value)\n        elif type_hint in (str, Any):\n            return env_value\n        elif type_hint is list or origin is list or origin is List:\n            # Env values are often hand-edited (trailing commas, single quotes).\n            # Bare `list` has get_origin(None); typing.List[...] has origin list.\n            try:\n                value = json_repair.loads(env_value)\n            except Exception as exc:\n                raise ValueError(f\"Cannot convert {env_value} to list\") from exc\n            if not isinstance(value, list):\n                raise ValueError(f\"Cannot convert {env_value} to list\")\n            return value\n        elif type_hint is dict:\n            try:\n                value = json_repair.loads(env_value)\n            except Exception as exc:\n                raise ValueError(f\"Cannot convert {env_value} to dict\") from exc\n            if not isinstance(value, dict):\n                raise ValueError(f\"Cannot convert {env_value} to dict\")\n            return value\n        else:\n            raise ValueError(f\"Unsupported type {type_hint} for key {key}\")\n\n\n    def set_verbose(self, verbose: bool) -> None:\n        \"\"\"Set the verbosity level.\"\"\"\n        self.llm_kwargs[\"verbose\"] = verbose","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/assafelovic/gpt-researcher/blob/6f998577d547b1e54ec662dac63583aa11e3b84b/gpt_researcher/config/config.py#L275-L311","documentation":"For list-typed config attributes, convert_env_value parses the env string with json_repair; if parsing raises (first site) this error is raised chained from the parse exception.","triggerScenarios":"A list-typed env var containing text json_repair cannot recover, e.g. DOC_PATH='just some words' where a JSON array was expected.","commonSituations":"Free-form text in a list env var; mismatched brackets; wrong var name putting a scalar value on a list field.","solutions":["Provide a JSON array: MYLIST='[\"a\",\"b\"]'","If you meant a path/string setting, move the value to the correct scalar variable"],"exampleFix":"# before\nSUBQUERIES=one two three\n# after\nSUBQUERIES=[\"one\",\"two\",\"three\"]","handlingStrategy":"validation","validationCode":"import json\nv = os.getenv(\"MY_LIST\", \"[]\")\ntry:\n    assert isinstance(json.loads(v), list)\nexcept Exception:\n    raise SystemExit(f\"MY_LIST must be a JSON array, got {v!r}\")","typeGuard":"def is_json_list(s: str) -> bool:\n    try:\n        return isinstance(json_repair.loads(s), list)\n    except Exception:\n        return False","tryCatchPattern":"try:\n    cfg = Config()\nexcept ValueError as e:\n    if \"to list\" in str(e):\n        os.environ[\"MY_LIST\"] = \"[]\"; cfg = Config()\n    else: raise","preventionTips":["Write list env vars as JSON arrays","Quote arrays in single quotes in .env"],"tags":["python","config","env-vars","json"],"backgroundTag":"env-var-type-conversion-failed","analyzedSha":"6f998577d547b1e54ec662dac63583aa11e3b84b","analyzedAt":"2026-08-28T17:50:07.383Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}