{
  "id": "python/pydantic-settings-env-parse-json",
  "signature": "pydantic_core._pydantic_core.ValidationError: 1 validation error for AppSettings\ndatabase_urls\n  Input should be a valid list [type=list_type, input_value='[\"db1\",\"db2\"]', input_type=str]",
  "signature_zh": "pydantic_core._pydantic_core.ValidationError: 1 个验证错误，字段 database_urls 输入应为有效列表 [type=list_type]",
  "regex": "pydantic_core\\._pydantic_core\\.ValidationError:\\ 1\\ validation\\ error\\ for\\ AppSettings\\\ndatabase_urls\\\n\\ \\ Input\\ should\\ be\\ a\\ valid\\ list\\ \\[type=list_type,\\ input_value='\\[\"db1\",\"db2\"\\]',\\ input_type=str\\]",
  "domain": "python",
  "category": "config_error",
  "subcategory": null,
  "root_cause": "pydantic-settings parses environment variables as strings by default. When a list-typed field is populated from an env var, the JSON string is not automatically decoded unless the field is annotated for complex parsing.",
  "root_cause_type": "generic",
  "root_cause_zh": "pydantic-settings 默认将环境变量作为字符串解析。当列表类型字段从环境变量填充时，JSON 字符串不会自动解码，除非字段被标注为复杂解析。",
  "versions": [
    {
      "version": "2.x",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "These settings control None handling and variable naming, not JSON decoding of complex types.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "The validator receives the raw string before type coercion, so isinstance(v, list) is False and the error is re-raised.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "",
      "success_rate": 0.9,
      "how": "from pydantic_settings import BaseSettings, SettingsConfigDict\nfrom pydantic import field_validator\nimport json\n\nclass AppSettings(BaseSettings):\n    model_config = SettingsConfigDict(env_file='.env')\n    database_urls: list[str]\n\n    @field_validator('database_urls', mode='before')\n    @classmethod\n    def parse_json(cls, v):\n        if isinstance(v, str):\n            return json.loads(v)\n        return v",
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "success_rate": 0.75,
      "how": "from pydantic_settings import BaseSettings, SettingsConfigDict\nfrom pydantic import Field\n\nclass AppSettings(BaseSettings):\n    database_urls: list[str] = Field(default_factory=list)",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": null,
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.8,
  "resolvable": "true",
  "first_seen": "2024-11-22",
  "last_confirmed": "2025-01-01",
  "last_updated": "2025-01-01",
  "evidence_count": 0,
  "tags": [],
  "locale": "en",
  "aliases": []
}