{"record":{"id":"4fb24dded9975453","repo":"assafelovic/gpt-researcher","slug":"cannot-convert-env-value-to-dict","errorCode":null,"errorMessage":"Cannot convert {env_value} to dict","messagePattern":"Cannot convert (.+?) to dict","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"gpt_researcher/config/config.py","lineNumber":301,"sourceCode":"        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\n\n    def get_mcp_server_config(self, name: str) -> dict:\n        \"\"\"\n        Get the configuration for an MCP server.\n        \n        Args:\n            name (str): The name of the MCP server to get the config for.\n                ","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/assafelovic/gpt-researcher/blob/6f998577d547b1e54ec662dac63583aa11e3b84b/gpt_researcher/config/config.py#L283-L319","documentation":"For dict-typed config attributes, convert_env_value parses the env string with json_repair; if parsing raises entirely, this ValueError is raised chained from the exception.","triggerScenarios":"A dict-typed env var with unparseable content, e.g. MYDICT='key: value' (not JSON) where json_repair gives up.","commonSituations":"YAML-style or Python-dict literals in env vars; missing braces; free text on a dict field.","solutions":["Use strict JSON object syntax: MYDICT='{\"k\":\"v\"}'","Quote inner strings; wrap the whole value in single quotes in .env so the shell keeps double quotes"],"exampleFix":"# before\nMYDICT={k: v}\n# after\nMYDICT='{\"k\": \"v\"}'","handlingStrategy":"validation","validationCode":"import json\nv = os.getenv(\"MY_DICT\", \"{}\")\njson.loads(v)  # raises early with clear context if unparseable","typeGuard":"def is_json_dict(s):\n    try:\n        return isinstance(json_repair.loads(s), dict)\n    except Exception:\n        return False","tryCatchPattern":"try:\n    cfg = Config()\nexcept ValueError as e:\n    if \"to dict\" in str(e):\n        print('Fix MY_DICT to JSON object syntax'); exit(2)\n    raise","preventionTips":["Use strict JSON for dict env vars","Wrap in single quotes in shell/.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"}